Last active
August 29, 2015 14:04
-
-
Save chenrui333/006667b99bc581af0e09 to your computer and use it in GitHub Desktop.
printout the files with subdirectory
This file contains 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 | |
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") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.