先网上找了个类似的功能:
// http://vipscu.blog.163.com/blog/static/181808372201221121244906/
目前需要
dir /B/S/ON %DATA_PATH%\%%i\*.xml > #anm.txt
把某个目录下的所有.xml文件都打印到#anm.txt文件中
并用MD5实现已处理文件过滤。
【已完成】
#定义 XCOPY
def XCOPY(sourceDir, targetDir, suff='*.*'):
if sourceDir.find(".svn") > 0:
return
for name in os.listdir(sourceDir):
if name == '.DS_Store':
print("ignore:.DS_Store")
continue
doCopy = False
if (suff == '*.*'):
doCopy = True
else:
if name.endswith(suff):
doCopy = True
if (doCopy):
sourceFile = os.path.join(sourceDir, name)
targetFile = os.path.join(targetDir, name)
if os.path.isfile(sourceFile):
if not os.path.exists(targetDir):
os.makedirs(targetDir)
print("直接拷贝文件到:"+ sourceFile)
shutil.copy(sourceFile,targetFile)
else:
XCOPY(sourceFile, targetFile)
#del 删除固定格式的文件
def DEL(sourceDir, suff):
if sourceDir.find(".svn") > 0:
return
for name in os.listdir(sourceDir):
sourceFile = os.path.join(sourceDir, name)
if os.path.isfile(sourceFile):
if name.endswith(suff):
os.remove(sourceFile)
print("删除文件:"+ sourceFile)
else:
DEL(sourceFile, suff)