Skip to content

Instantly share code, notes, and snippets.

@chenrui333
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chenrui333/006667b99bc581af0e09 to your computer and use it in GitHub Desktop.
Save chenrui333/006667b99bc581af0e09 to your computer and use it in GitHub Desktop.
printout the files with subdirectory
import os
filepath_root1 = "C:\\Users\\rchen\\directory"
file_to_write = "./samplefile.txt"
with open(file_to_write, "w") as myfile:
for path, subdirs, files in os.walk(filepath_root1):
for name in files:
path = path.replace(filepath_root1, "")
myfile.write(os.path.join(path, name) + "\n")
@chenrui333
Copy link
Author

ref link: http://stackoverflow.com/questions/1192978/python-get-relative-path-of-all-files-and-subfolders-in-a-directory
maybe root.replace(myFolder, "") should change to root.replace(myFolder, "", 1) to avoid potential sth. you know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment