Selecting and Copying a Random File Several Times
Posted
by
user1252778
on Stack Overflow
See other posts from Stack Overflow
or by user1252778
Published on 2012-03-06T16:56:47Z
Indexed on
2012/04/11
23:29 UTC
Read the original article
Hit count: 241
python
|python-3.x
[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!')
© Stack Overflow or respective owner