-
-
Save kparms/6efe54e19809df9e96ece274c7385d74 to your computer and use it in GitHub Desktop.
Python script to generate a text file listing all files from a given directory (including those in sub-folders).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
# start editable vars # | |
outputfile = "inventory.txt" # file to save the results to | |
folder = "C:\\Users\\[User]\\Documents" # the folder to inventory | |
exclude = ['Thumbs.db','.tmp'] # exclude files containing these strings | |
pathsep = "\\" # path seperator ('/' for linux, '\\' for Windows) | |
# end editable vars # | |
with open(outputfile, "w") as txtfile: | |
for path,dirs,files in os.walk(folder): | |
sep = "\n---------- " + path.split(pathsep)[len(path.split(pathsep))-1] + " ----------" | |
print sep | |
#txtfile.write("%s\n" % sep) | |
for fn in sorted(files): | |
if not any(x in fn for x in exclude): | |
filename = os.path.join(path, fn) | |
print filename | |
txtfile.write("%s\n" % filename) | |
txtfile.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment