def mycopyfile(srcfile, dstpath): # 复制函数
if not os.path.isfile(srcfile):
print("%s not exist!" % (srcfile))
else:
fpath, fname = os.path.split(srcfile) # 分离文件名和路径
if not os.path.exists(dstpath):
os.makedirs(dstpath) # 创建路径
shutil.copy(srcfile, dstpath + fname) # 复制文件
print("copy %s -> %s" % (srcfile, dstpath + fname))
# src_dir = './'
# dst_dir = './copy/' # 目的路径记得加斜杠
# src_file_list = glob(src_dir + '*') # glob获得路径下所有文件,可根据需要修改
# for srcfile in src_file_list:
# mycopyfile(srcfile, dst_dir) # 复制文件
python文件移动到文件夹
最新推荐文章于 2024-05-14 11:32:26 发布