does anyone know if there exists a library that will give a snapshot image of a directory structure ?
if not, is there an easy pro开发者_高级运维gramming approach to creating this in c# or python?
Like this?
import os, sys
for root, dirs, files in os.walk(sys.argv[1]):
full_path = os.path.abspath(root)
chunks = full_path.split(os.path.sep)
depth = len(chunks) - 2
indent = ' ' * depth
print indent + full_path
I'm not sure what you mean by "snapshot image" of a directory structure, but it is likely that you can do what you need rather easily.
For example, in Python, the os.walk can be used to navigate a directory of your choice.
import os
rootdir='C:\path\to\directory'
def parseobj(parent, tab):
for child in parent:
if type(child) == list:
tab = tab + 1
parseobj(child, tab)
else:
for t in range(0,tab): print '\t',
print '\\',
print child
for obj in os.walk(rootdir):
tab = 0
if type(obj) == tuple:
parseobj(obj, tab)
else:
print obj
精彩评论