Skip to content

Instantly share code, notes, and snippets.

@spdin
Last active July 28, 2023 22:52
Show Gist options
  • Save spdin/9a693f2f0cd4195718423d24d308dc0a to your computer and use it in GitHub Desktop.
Save spdin/9a693f2f0cd4195718423d24d308dc0a to your computer and use it in GitHub Desktop.
Pick and move file to another folder randomly
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)
@pythonlover22
Copy link

Good job. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment