os: Implement walk().

pull/118/head
Paul Sokolovsky 2014-05-14 20:39:31 +03:00
rodzic 07c659e879
commit 061f56a14d
1 zmienionych plików z 19 dodań i 0 usunięć

Wyświetl plik

@ -2,6 +2,7 @@ import ffi
import array
import struct
import errno
import stat as stat_
try:
from _os import *
except:
@ -81,6 +82,24 @@ def listdir(path="."):
res.append(fname)
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):
buf = bytearray(n)
r = read_(fd, buf, n)