按照定义的比例移动图片到另一个文件夹,需要改动:
- rate:比例(0.1表示随机移动10%的图片)
- fileDir:原图片数据文件夹路径
- tarDir:另一个文件夹的路径
import os, random, shutil
def moveFile(fileDir):
pathDir = os.listdir(fileDir)
filenumber = len(pathDir)
rate = 0.1 # Pickup rate
picknumber = int(filenumber * rate)
sample = random.sample(pathDir, picknumber)
print(sample)
for name in sample:
shutil.move(fileDir + name, tarDir + name)
return
if __name__ == '__main__':
fileDir = "path1/" # Source path
tarDir = 'path2/' # Target path
print("Start")
moveFile(fileDir)
print("Finish")
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)