python随机选取10000张图片并复制到另一个文件夹中

来源:互联网 发布:借身份证给别人开淘宝 编辑:程序博客网 时间:2024/06/05 11:20
# author by LYS 2017/5/24# for Deep Learning course'''1. read the whole files under a certain folder2. chose 10000 files randomly3. copy them to another folder and save'''import os, random, shutildef copyFile(fileDir):    # 1pathDir = os.listdir(fileDir)    # 2sample = random.sample(pathDir, 10000)print sample# 3for name in sample:shutil.copyfile(fileDir+name, tarDir+name)if __name__ == '__main__':fileDir = "/home/lys/img_align_celeba_png/"tarDir = '/home/lys/celebA/'copyFile(fileDir)
遇到的问题:
 shell命令行下for循环内部要有四个空格;回车两次for循环执行;copy文件时,目录最后要有/,否则直接把文件名字添加在了目录后面,更改路径
阅读全文
0 0
原创粉丝点击