python - randomly choose 100 documents under a directory -


there 2000 documents under directory. want randomly select documents , copy them new directory automatically.

some relevant information generating 1 document name under directory.

try:

import shutil, random, os filenames = random.sample(os.listdir(dirpath), 100) fname in filenames: srcpath = os.path.join(dirpath, fname)) shutil.copyfile(srcpath, destdirectory) 

Comments

Popular posts from this blog

JQuery Autocomplete without using label, value, id -

c++ - Accessing inactive union member and undefined behavior? -

JAVA - what is the difference between void and boolean methods? -