kopia lustrzana https://github.com/micropython/micropython-lib
os: Reimplement listdir() in terms of iterator.
rodzic
232e62e62a
commit
07c659e879
|
@ -59,7 +59,7 @@ def makedirs(name, mode=0o777, exist_ok=False):
|
||||||
if e.args[0] != errno.EEXIST:
|
if e.args[0] != errno.EEXIST:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def listdir(path="."):
|
def ilistdir_ex(path="."):
|
||||||
dir = opendir_(path)
|
dir = opendir_(path)
|
||||||
if not dir:
|
if not dir:
|
||||||
raise_error()
|
raise_error()
|
||||||
|
@ -71,6 +71,11 @@ def listdir(path="."):
|
||||||
break
|
break
|
||||||
dirent = ffi.as_bytearray(dirent, struct.calcsize(dirent_fmt))
|
dirent = ffi.as_bytearray(dirent, struct.calcsize(dirent_fmt))
|
||||||
dirent = struct.unpack(dirent_fmt, dirent)
|
dirent = struct.unpack(dirent_fmt, dirent)
|
||||||
|
yield dirent
|
||||||
|
|
||||||
|
def listdir(path="."):
|
||||||
|
res = []
|
||||||
|
for dirent in ilistdir_ex(path):
|
||||||
fname = str(dirent[4].split('\0', 1)[0], "ascii")
|
fname = str(dirent[4].split('\0', 1)[0], "ascii")
|
||||||
if fname != "." and fname != "..":
|
if fname != "." and fname != "..":
|
||||||
res.append(fname)
|
res.append(fname)
|
||||||
|
|
Ładowanie…
Reference in New Issue