kopia lustrzana https://github.com/micropython/micropython-lib
os: Implement walk().
rodzic
07c659e879
commit
061f56a14d
|
@ -2,6 +2,7 @@ import ffi
|
||||||
import array
|
import array
|
||||||
import struct
|
import struct
|
||||||
import errno
|
import errno
|
||||||
|
import stat as stat_
|
||||||
try:
|
try:
|
||||||
from _os import *
|
from _os import *
|
||||||
except:
|
except:
|
||||||
|
@ -81,6 +82,24 @@ def listdir(path="."):
|
||||||
res.append(fname)
|
res.append(fname)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
def walk(top, topdown=True):
|
||||||
|
files = []
|
||||||
|
dirs = []
|
||||||
|
for dirent in ilistdir_ex(top):
|
||||||
|
mode = dirent[3] << 12
|
||||||
|
fname = str(dirent[4].split('\0', 1)[0], "ascii")
|
||||||
|
if stat_.S_ISDIR(mode):
|
||||||
|
if fname != "." and fname != "..":
|
||||||
|
dirs.append(fname)
|
||||||
|
else:
|
||||||
|
files.append(fname)
|
||||||
|
if topdown:
|
||||||
|
yield top, dirs, files
|
||||||
|
for d in dirs:
|
||||||
|
yield from walk(top + "/" + d, topdown)
|
||||||
|
if not topdown:
|
||||||
|
yield top, dirs, files
|
||||||
|
|
||||||
def read(fd, n):
|
def read(fd, n):
|
||||||
buf = bytearray(n)
|
buf = bytearray(n)
|
||||||
r = read_(fd, buf, n)
|
r = read_(fd, buf, n)
|
||||||
|
|
Ładowanie…
Reference in New Issue