【python写批处理】仿dir命令

先网上找了个类似的功能:

// 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)


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值