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
Post a Comment