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

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -