import os
import shutil
def copyfile(source_path,target_path,target_path2):
print(target_path)
if not os.path.exists(target_path2):
# 如果目标路径不存在原文件夹的话就创建
os.makedirs(target_path2)
target_path3 = target_path + '-1'
if os.path.exists(target_path) == True:
print(os.path.exists(target_path))
os.rename(target_path,target_path3)
shutil.move(source_path, target_path)
if os.path.exists(target_path) == False:
print(os.path.exists(target_path))
shutil.move(source_path, target_path)
def copyfiles():
#文件原始位置
LocalDir =
for djbh in os.listdir(LocalDir):
local_path = os.path.join(LocalDir, djbh)
print(djbh)
print(local_path)
year = djbh[0:4]
monthday = djbh[4:8]
#文件应存放位置上级目录
RemoteDir =
#文件应存放位置
RemoteDir2 =
copyfile(local_path, RemoteDir2,RemoteDir)
print('copy dir finished!')
copyfiles()
|