Last active
July 28, 2023 22:52
-
-
Save spdin/9a693f2f0cd4195718423d24d308dc0a to your computer and use it in GitHub Desktop.
Pick and move file to another folder randomly
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, random, shutil | |
#Prompting user to enter number of files to select randomly along with directory | |
source=input("Enter the Source Directory : ") | |
dest=input("Enter the Destination Directory : ") | |
no_of_files=int(input("Enter The Number of Files To Select : ")) | |
print("%"*25+"{ Details Of Transfer }"+"%"*25) | |
print("\n\nList of Files Moved to %s :-"%(dest)) | |
#Using for loop to randomly choose multiple files | |
for i in range(no_of_files): | |
#Variable random_file stores the name of the random file chosen | |
random_file=random.choice(os.listdir(source)) | |
print("%d} %s"%(i+1,random_file)) | |
source_file="%s/%s"%(source,random_file) | |
dest_file=dest | |
#"shutil.move" function moves file from one directory to another | |
shutil.move(source_file,dest_file) | |
print("\n\n"+"$"*33+"[ Files Moved Successfully ]"+"$"*33) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Good job. Thank you!