当前位置: 首页>>代码示例>>Python>>正文


Python uos.listdir方法代码示例

本文整理汇总了Python中uos.listdir方法的典型用法代码示例。如果您正苦于以下问题:Python uos.listdir方法的具体用法?Python uos.listdir怎么用?Python uos.listdir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在uos的用法示例。


在下文中一共展示了uos.listdir方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Apps

# 需要导入模块: import uos [as 别名]
# 或者: from uos import listdir [as 别名]
def Apps(self, data=None):
        self.destroy()
        self.create_window(show=False)
        self.btngroup = ButtonGroup(self.window, 40, 30, 240, 40, 10)
        self.widgets.append(self.btngroup)
        for app in uos.listdir('/apps'):
            try:
                with open('/apps/{}/app.json'.format(app)) as fp:
                    data = json.load(fp)
            except Exception as e:
                print(e)
                continue
            if 'name' in data:
                self.btngroup.add(data['name'], self.run_app, data=app)
        self.btngroup.end()
        self.window.show() 
开发者ID:IBM-Developer-Korea,项目名称:developer-badge-2018-apps,代码行数:18,代码来源:launcher.py

示例2: generate_dir_listing

# 需要导入模块: import uos [as 别名]
# 或者: from uos import listdir [as 别名]
def generate_dir_listing(self, absolute_path):
        path = absolute_path[len(self._root_path):]
        if not path:
            path = '/'
        data = "<html><body><header><em>uhttpd/{}</em><hr></header><h1>{}</h1><ul>".format(uhttpd.VERSION, path)
        components = self.components(path)
        components_len = len(components)
        if components_len > 0:
            data += "<li><a href=\"{}\">..</a></li>\n".format(self.to_path(components[:components_len-1]))
        files = listdir(absolute_path)
        for f in files:
            tmp = components.copy()
            tmp.append(f)
            data += "<li><a href=\"{}\">{}</a></li>\n".format(self.to_path(tmp), f)
        data += "</ul></body></html>"
        data = data.encode('UTF-8')
        body = lambda stream: stream.awrite(data)
        return len(data), body 
开发者ID:fadushin,项目名称:esp8266,代码行数:20,代码来源:file_handler.py

示例3: write_handler

# 需要导入模块: import uos [as 别名]
# 或者: from uos import listdir [as 别名]
def write_handler(pin, values):
    if values:
        in_args = values[0].split(' ')
        cmd = in_args[0]
        cmd_args = in_args[1:]

        if cmd == 'help':
            output = ' '.join(CMD_LIST)
        elif cmd == CMD_LIST[0]:
            output = blynklib.LOGO
        elif cmd == CMD_LIST[1]:
            output = blynklib.__version__
        elif cmd == CMD_LIST[2]:
            output = uos.uname()
        elif cmd == CMD_LIST[3]:
            arg = cmd_args[0] if cmd_args else ''
            output = uos.listdir(arg)
        else:
            output = "[ERR]: Not supported command '{}'".format(values[0])

        blynk.virtual_write(pin, output)
        blynk.virtual_write(pin, '\n') 
开发者ID:blynkkk,项目名称:lib-python,代码行数:24,代码来源:02_terminal_cli.py

示例4: format

# 需要导入模块: import uos [as 别名]
# 或者: from uos import listdir [as 别名]
def format(self):
        import uos
        log.info("Formatting filesystem ...")

        while uos.listdir("/"):
            lst = uos.listdir("/")
            uos.chdir("/")
            while lst:
                try:
                    uos.remove(lst[0])
                    log.info("Removed '" + uos.getcwd() + "/" + lst[0] + "'")
                    lst = uos.listdir(uos.getcwd())
                except:
                    dir = lst[0]
                    log.info("Directory '" + uos.getcwd() + "/" + dir + "' detected. Opening it...")
                    uos.chdir(dir)
                    lst = uos.listdir(uos.getcwd())
                    if len(lst) == 0:
                        log.info("Directory '" + uos.getcwd() + "' is empty. Removing it...")
                        uos.chdir("..")
                        uos.rmdir(dir)
                        break

        log.info("Format completed successfully") 
开发者ID:idimitrakopoulos,项目名称:illuminOS,代码行数:26,代码来源:Board.py

示例5: isdir

# 需要导入模块: import uos [as 别名]
# 或者: from uos import listdir [as 别名]
def isdir(path):
    try:
        os.listdir(path)
        return True
    except:
        return False 
开发者ID:m5stack,项目名称:UIFlow-Code,代码行数:8,代码来源:utils.py

示例6: startup

# 需要导入模块: import uos [as 别名]
# 或者: from uos import listdir [as 别名]
def startup(timer=None):
    conf = Config('global')
    for app in uos.listdir('/apps'):
        try:
            uos.stat('/apps/{}/boot.py'.format(app))
        except OSError:
            pass
        else:
            execfile('/apps/{}/boot.py'.format(app))
            gc.collect()
    del conf
    gc.collect() 
开发者ID:IBM-Developer-Korea,项目名称:developer-badge-2018-apps,代码行数:14,代码来源:util.py

示例7: send_list_data

# 需要导入模块: import uos [as 别名]
# 或者: from uos import listdir [as 别名]
def send_list_data(self, path, dataclient, full):
        try: # whether path is a directory name
            for fname in sorted(uos.listdir(path), key = str.lower):
                dataclient.sendall(self.make_description(path, fname, full))
        except: # path may be a file name or pattern
            pattern = path.split("/")[-1]
            path = path[:-(len(pattern) + 1)]
            if path == "": path = "/"
            for fname in sorted(uos.listdir(path), key = str.lower):
                if fncmp(fname, pattern) == True:
                    dataclient.sendall(self.make_description(path, fname, full)) 
开发者ID:lemariva,项目名称:uPyPortal,代码行数:13,代码来源:ftp.py

示例8: is_dir

# 需要导入模块: import uos [as 别名]
# 或者: from uos import listdir [as 别名]
def is_dir(path):
    try:
        listdir(path)
        return True
    except OSError:
        return False 
开发者ID:fadushin,项目名称:esp8266,代码行数:8,代码来源:file_handler.py

示例9: listdir

# 需要导入模块: import uos [as 别名]
# 或者: from uos import listdir [as 别名]
def listdir(path):
    import sys
    if sys.platform == 'esp8266':
        return uos.listdir(path)
    else:
        ret = []
        for name, size, modified in uos.ilistdir(path):
            ret.append(name)
        if ret == []:
            raise OSError()
        return ret 
开发者ID:fadushin,项目名称:esp8266,代码行数:13,代码来源:file_handler.py

示例10: send_list_data

# 需要导入模块: import uos [as 别名]
# 或者: from uos import listdir [as 别名]
def send_list_data(path, dataclient, full):
    try:  # whether path is a directory name
        for fname in sorted(uos.listdir(path), key=str.lower):
            dataclient.sendall(make_description(path, fname, full))
    except:  # path may be a file name or pattern
        pattern = path.split("/")[-1]
        path = path[:-(len(pattern) + 1)]
        if path == "":
            path = "/"
        for fname in sorted(uos.listdir(path), key=str.lower):
            if fncmp(fname, pattern):
                dataclient.sendall(make_description(path, fname, full)) 
开发者ID:robert-hh,项目名称:FTP-Server-for-ESP8266-ESP32-and-PYBD,代码行数:14,代码来源:ftp.py

示例11: send_list_data

# 需要导入模块: import uos [as 别名]
# 或者: from uos import listdir [as 别名]
def send_list_data(self, path, data_client, full):
        try:
            for fname in uos.listdir(path):
                data_client.sendall(self.make_description(path, fname, full))
        except:  # path may be a file name or pattern
            path, pattern = self.split_path(path)
            try:
                for fname in uos.listdir(path):
                    if self.fncmp(fname, pattern):
                        data_client.sendall(
                            self.make_description(path, fname, full))
            except:
                pass 
开发者ID:robert-hh,项目名称:FTP-Server-for-ESP8266-ESP32-and-PYBD,代码行数:15,代码来源:uftpd.py

示例12: rmdir

# 需要导入模块: import uos [as 别名]
# 或者: from uos import listdir [as 别名]
def rmdir(self, directory, missing_okay=False):
        """Forcefully remove the specified directory and all its children."""
        # Build a script to walk an entire directory structure and delete every
        # file and subfolder.  This is tricky because MicroPython has no os.walk
        # or similar function to walk folders, so this code does it manually
        # with recursion and changing directories.  For each directory it lists
        # the files and deletes everything it can, i.e. all the files.  Then
        # it lists the files again and assumes they are directories (since they
        # couldn't be deleted in the first pass) and recursively clears those
        # subdirectories.  Finally when finished clearing all the children the
        # parent directory is deleted.
        command = """
            try:
                import os
            except ImportError:
                import uos as os
            def rmdir(directory):
                os.chdir(directory)
                for f in os.listdir():
                    try:
                        os.remove(f)
                    except OSError:
                        pass
                for f in os.listdir():
                    rmdir(f)
                os.chdir('..')
                os.rmdir(directory)
            rmdir('{0}')
        """.format(
            directory
        )
        self._pyboard.enter_raw_repl()
        try:
            out = self._pyboard.exec_(textwrap.dedent(command))
        except PyboardError as ex:
            message = ex.args[2].decode("utf-8")
            # Check if this is an OSError #2, i.e. directory doesn't exist
            # and rethrow it as something more descriptive.
            if message.find("OSError: [Errno 2] ENOENT") != -1:
                if not missing_okay:
                    raise RuntimeError("No such directory: {0}".format(directory))
            else:
                raise ex
        self._pyboard.exit_raw_repl() 
开发者ID:scientifichackers,项目名称:ampy,代码行数:46,代码来源:files.py


注:本文中的uos.listdir方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。