Python uos.listdir() Examples
The following are 13
code examples of uos.listdir().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
uos
, or try the search function
.
Example #1
Source File: launcher.py From developer-badge-2018-apps with Apache License 2.0 | 6 votes |
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()
Example #2
Source File: file_handler.py From esp8266 with BSD 2-Clause "Simplified" License | 6 votes |
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
Example #3
Source File: 02_terminal_cli.py From lib-python with MIT License | 6 votes |
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')
Example #4
Source File: Board.py From illuminOS with MIT License | 6 votes |
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")
Example #5
Source File: utils.py From UIFlow-Code with GNU General Public License v3.0 | 5 votes |
def isdir(path): try: os.listdir(path) return True except: return False
Example #6
Source File: util.py From developer-badge-2018-apps with Apache License 2.0 | 5 votes |
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()
Example #7
Source File: ftp.py From uPyPortal with Apache License 2.0 | 5 votes |
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))
Example #8
Source File: file_handler.py From esp8266 with BSD 2-Clause "Simplified" License | 5 votes |
def is_dir(path): try: listdir(path) return True except OSError: return False
Example #9
Source File: file_handler.py From esp8266 with BSD 2-Clause "Simplified" License | 5 votes |
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
Example #10
Source File: ftp.py From FTP-Server-for-ESP8266-ESP32-and-PYBD with MIT License | 5 votes |
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))
Example #11
Source File: uftpd.py From FTP-Server-for-ESP8266-ESP32-and-PYBD with MIT License | 5 votes |
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
Example #12
Source File: ftp_thread.py From FTP-Server-for-ESP8266-ESP32-and-PYBD with MIT License | 5 votes |
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))
Example #13
Source File: files.py From ampy with MIT License | 4 votes |
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()