I want to process all files in a directory that is python, A memo to forget every time.
fild_all_files.py
def fild_all_files(directory):
for root, dirs, files in os.walk(directory):
yield root
for file in files:
yield os.path.join(root, file)
Just pass the path of the target directory as an argument and loop, and the contents of the file will be returned.
main.py
for filename in fild_all_files(file_dir):
print filename
that's all
Recommended Posts