/ Published in: Python

Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#################################################### ## ## Prints a dir structure to a text file ## ## Usage : python printdir.py [path ala z:/mypath or /mypath/foo ## #################################################### import os, sys dir = sys.argv[1] outName = 'dirpaths.txt' f = open(outName,'w') # write initial dir for reference f.write (dir + '\n') count = 0 for item in os.walk(dir): count = count + 1 item = item[0].replace('\\','/') curPath = item.split('/') if count == 1: curPath = item else: curPath = '\t' * (len(curPath)-1) + curPath[len(curPath)-1] f.write(curPath + '\n') print curPath f.close if os.path.exists(outName) : print 'File saved to: %s' % (outName)
Comments
