mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 02:42:49 -04:00
listdir, walk
This commit is contained in:
parent
2337616f94
commit
0f52801b0c
@ -5,7 +5,7 @@ SIMPLE_THREADS model, by avoiding blocking all threads while waiting
|
|||||||
for I/O to complete. """
|
for I/O to complete. """
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
'file', 'open',
|
'file', 'open', 'listdir', 'walk'
|
||||||
]
|
]
|
||||||
|
|
||||||
from pandac import PandaModules as pm
|
from pandac import PandaModules as pm
|
||||||
@ -244,3 +244,39 @@ class file:
|
|||||||
self.__lastWrite = True
|
self.__lastWrite = True
|
||||||
|
|
||||||
open = file
|
open = file
|
||||||
|
|
||||||
|
def listdir(path):
|
||||||
|
""" Implements os.listdir over vfs. """
|
||||||
|
files = []
|
||||||
|
for file in _vfs.scanDirectory(path):
|
||||||
|
files.append(file.getFilename().getBasename())
|
||||||
|
return files
|
||||||
|
|
||||||
|
def walk(top, topdown = True, onerror = None, followlinks = True):
|
||||||
|
""" Implements os.walk over vfs.
|
||||||
|
|
||||||
|
Note: we don't support onerror or followlinks; errors are ignored
|
||||||
|
and links are always followed. """
|
||||||
|
|
||||||
|
dirnames = []
|
||||||
|
filenames = []
|
||||||
|
|
||||||
|
for file in _vfs.scanDirectory(top):
|
||||||
|
if file.isDirectory():
|
||||||
|
dirnames.append(file.getFilename().getBasename())
|
||||||
|
else:
|
||||||
|
filenames.append(file.getFilename().getBasename())
|
||||||
|
|
||||||
|
if topdown:
|
||||||
|
yield (top, dirnames, filenames)
|
||||||
|
|
||||||
|
for dir in dirnames:
|
||||||
|
next = '%s/%s' % (top, dir)
|
||||||
|
for tuple in walk(next, topdown = topdown):
|
||||||
|
yield tuple
|
||||||
|
|
||||||
|
if not topdown:
|
||||||
|
yield (top, dirnames, filenames)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user