CyLouisKoo
3/25/2018 - 4:07 AM

shutil

随机复制文件从A目录到B目录

fileDir = 'A'
tarDir = 'B' 
import os, random, shutil  
  
def copyFile(fileDir):  
 
    pathDir = os.listdir(fileDir)  
 
    sample = random.sample(pathDir, 10000)   
    for name in sample:  
        shutil.copyfile(fileDir+name, tarDir+name)  
if __name__ == '__main__':
    copyFile(fileDir)