Selecting and Copying a Random File Several Times
- by user1252778
[Edit: see below for final code] I have the following code and I'm trying to figure out where to insert the random.choice code to make it select a single file, copy it, and repeat (here 6 times).
import os
import shutil
import random
dir_input = str(input("Enter Source Directory: "))
src_files = (os.listdir(dir_input))
for x in range (0,5):
print ('This is the %d time' % x)
for file_name in src_files:
full_file_name = (os.path.join(dir_input, file_name))
if (os.path.isfile(full_file_name)):
print ('copying...' + full_file_name)
shutil.copy(full_file_name, r'C:\Dir'))
else:
print ('Finished!')