#! /usr/bin/env python
# coding:utf-8
import os
import shutil
import time
RootB = r"C:\Users\dell\Desktop\ClientB"
RootA = r"C:\Users\dell\Desktop\ClientA"
DestA = "E:\DataShare\ClientA"
DestB = "E:\DataShare\ClientB"
def copyDirAllFiles(src_Dir, dst_Dir):
for (root, dirs, files) in os.walk(src_Dir):
new_root = root.replace(src_Dir, dst_Dir, 1)
if not os.path.exists(new_root):
os.mkdir(new_root)
for d in dirs:
d = os.path.join(new_root, d)
if not os.path.exists(d):
os.mkdir(d)
for f in files:
# 把文件名分解为 文件名.扩展名
(shotname, extension) = os.path.splitext(f)
# 原文件的路径
old_path = os.path.join(root, f)
new_name = shotname + extension
# 新文件的路径
new_path = os.path.join(new_root, new_name)
try:
# 复制文件
# print("[new_path]:%s"%new_path)
shutil.copy(os.path.join(root, f), new_path)
except IOError as e:
print(e)
if __name__ == "__main__":
jog = True
while True:
time.sleep(2)
noneA = not os.listdir(DestA)
noneB = not os.listdir(DestB)
if noneA and noneB: # 两者同时为空,进行存放
if jog :
copyDirAllFiles(RootB, DestB)
print('---放入B端')
else:
copyDirAllFiles(RootA, DestA)
print('---放入A端')
jog = not jog
08-12
739

02-18
1133

07-06
8116

02-01