import os
import natsort
from natsort import natsorted
import shutil
# 1.记录某个目录下的文件名
image_root = "/media/jaychen/cj/iSAID_896_384/val/images"
txtfilepath = "/media/jaychen/cj/iSAID_896_384/val/imagesname.txt"
for root, dirs, files in os.walk(image_root):
files = natsorted(files)
with open(txtfilepath, 'w') as wf:
for f in files:
wf.write(f+"\n")
# # 2. 拷贝指定数量的文件
image_root = "/media/jaychen/cj/iSAID_896_384/val/images"
to_root = "/media/jaychen/cj/iSAID_debug/val/images" # 目标文件夹
txtfilepath = "/media/jaychen/cj/iSAID_896_384/val/imagesname.txt"
num = 32*3 # 要拷贝的文件数量
with open(txtfilepath, "r") as rf:
for i in range(num):
fname = rf.readline().splitlines()[0]
fpath = image_root+"/"+fname
tpath = to_root+"/"+fname
shutil.copyfile(fpath, tpath)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)