Created
February 22, 2023 06:15
-
-
Save firedynasty/5df5cccc9eb41621e7eac679d1c14a16 to your computer and use it in GitHub Desktop.
file mover with Python
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 | |
import shutil | |
import random | |
sourcepath = "/Users/name/screenshots" | |
destpath = "/Users/name/" | |
file_names = os.listdir(sourcepath) | |
file_dict = { | |
"hello" : "documents/linkedin/projects/file-sorter", | |
"loc1": "documents/linkedin/job_listings/taken_screenshots" | |
} | |
#if the file has hello in it, will move to documents/linkedin/projects/file-sorter | |
# Generate a random 4-digit number | |
random_number = random.randint(1000, 9999) | |
for file in file_names: | |
for keyword, folder in file_dict.items(): | |
if keyword in file: | |
# Add the random number to the file name | |
new_file_name = f"{random_number}_{file}" | |
# Move the file with the new name | |
shutil.move(os.path.join(sourcepath, file), os.path.join(destpath, folder, new_file_name)) | |
# Print the confirmation message | |
print(f"Moved {file} to {os.path.join(destpath, folder, new_file_name)}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment