Skip to content

Instantly share code, notes, and snippets.

@rickkk856
Forked from spdin/move_random.py
Created July 2, 2021 20:22
Show Gist options
  • Save rickkk856/f728d238f79086001f1435402ee33096 to your computer and use it in GitHub Desktop.
Save rickkk856/f728d238f79086001f1435402ee33096 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment