D盘下有个A文件夹,A文件夹中有两种命名形式的TXT文件,一种是 只有日期的 20111102.txt, 还有一种是 日期加行数的文件 20111102_56942.txt,现在需要一个批处理文件,讲A中得 日期_行数.txt 这种形式的文件复制到 D盘下的B文件夹中,怎么用批处理来实现?
------解决方案--------------------
- Python code
#!/usr/bin/python #encoding=utf-8 import shutil import os import re src = "A" des = "B" patterm = re.compile("_") list = os.listdir(src) for file in list: print(file,end='...') result = patterm.search(file) if result is not None: shutil.copy(os.path.join(src,file),os.path.join(des,file)) print("Moved") else: print("Not moved")
------解决方案--------------------
[code=CMD]
copy D:\A\*_*.txt D:\B\
[/code]
------解决方案--------------------
以前的代码,改改就行了。
- Python code
def copyLib(): currdir = os.getcwd() for root ,subdir,files in os.walk(currdir): for name in files: filepos = os.path.join(root, name) subdir = None subdir = root.replace(currdir,'') #print 'sub-',subdir filename= os.path.join(installDir + subdir, name) if not os.path.exists(os.path.dirname(filename)): os.makedirs(os.path.dirname(filename)) if os.path.isdir(filename): continue if os.path.isfile(filepos): print 'file from',filepos,'copy to',filename shutil.copy(filepos, filename) if name != "mediaServer.cfg": os.chmod(filename, 700) return
------解决方案--------------------
copy d:\A\????????_*.txt d:\B\
如果*用在开始,后面再写什么表达式都没用了,印象中是这样的
所以开头用8个?匹配时间。