There are about 2000 documents under the directory. I want to randomly select some documents and copy them to a new directory automatically.
Some relevant information about generating one document name under a certain directory.
There are about 2000 documents under the directory. I want to randomly select some documents and copy them to a new directory automatically.
Some relevant information about generating one document name under a certain directory.
Try:
import shutil, random, os
dirpath = 'your/read/location'
destDirectory = 'your/destination'filenames = random.sample(os.listdir(dirpath), 100)
for fname in filenames:srcpath = os.path.join(dirpath, fname)shutil.copyfile(srcpath, destDirectory)