Created
November 23, 2021 17:55
-
-
Save thedanhub/001c0f3263e2cabd60ebc188bd34f9ce to your computer and use it in GitHub Desktop.
List all files of a specified file type inside a directory and its subdirectories, and copy them to a separate folder with no subdirectories
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 | |
import shutil | |
folder_path = '/path/to/source/folder/' | |
export_path = '/path/to/export/folder' | |
number_of_files = 0 | |
for dirs, subdirs, files in os.walk(folder_path): | |
number_of_files = number_of_files+len(files) | |
for file in files: | |
if file.endswith(".pdf"): | |
print(file) | |
filepath = dirs + os.sep + file | |
print("Copying " + filepath) | |
shutil.copy2(filepath, export_path) | |
print('-----------') | |
print("Exported " + str(number_of_files) + " files to " + export_path + ".") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment