批处理复制文件解决方案


        批处理复制文件<br />

D盘下有个A文件夹,A文件夹中有两种命名形式的TXT文件,一种是 只有日期的 20111102.txt, 还有一种是 日期加行数的文件 2011110256942.txt,现在需要一个批处理文件,讲A中得 日期行数.txt 这种形式的文件复制到 D盘下的B文件夹中,怎么用批处理来实现?

Web后端 Web开发 程序开发

Staying 10 years, 1 month ago


copy d:\A\    _.txt d:\B\
如果
用在开始,后面再写什么表达式都没用了,印象中是这样的
所以开头用8个?匹配时间。

红白悲剧了 answered 10 years, 1 month ago


以前的代码,改改就行了。

  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

我什么都不会说 answered 10 years, 1 month ago


[code=CMD]
copy D:\A*_*.txt D:\B\
[/code]

星期八考博 answered 10 years, 1 month ago


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

whyisme answered 10 years, 1 month ago

Your Answer