创建一个名为 copyfile.py 的python文件
touch copyfile.py
···
# encoding: utf-8
import os
import shutil
import time
time0 = "2019-02-01"#起始日期
time1 = "2019-02-02"#结束日期
targetDir = r"D:game"#目标目录
print("正在处理,请稍等.....")
curDir = os.getcwd()
for root, dirs, files in os.walk(curDir):
#先创建目标目录
curFolder = root[len(curDir)+1:] #提取当前文件夹
tempTargetDir = os.path.join(targetDir, curFolder) #生成目标目录绝对路径
# print(tempTargetDir)
if os.path.exists(tempTargetDir):
shutil.rmtree(tempTargetDir)
#再拷贝文件
t0 = time.mktime(time.strptime(time0, "%Y-%m-%d"))
t1 = time.mktime(time.strptime(time1, "%Y-%m-%d"))+3600*24
for fileName in files:
absFileName = os.path.join(root, fileName)
if os.path.splitext(absFileName)[1] != '.py' and os.path.getmtime(absFileName) >= t0 and os.path.getmtime(absFileName) <= t1:
if not os.path.exists(tempTargetDir):
os.makedirs(tempTargetDir)
print("正在拷贝文件:", absFileName)
shutil.copy(absFileName, tempTargetDir)
os.system("pause")
···
执行方式 python copyfile.py