Board logo

标题: [文件操作] 批处理怎样copy指定时间和文件夹的文件到特定文件夹下(无需拷贝子目录)? [打印本页]

作者: caiyukou    时间: 2012-8-22 16:52     标题: 批处理怎样copy指定时间和文件夹的文件到特定文件夹下(无需拷贝子目录)?

我是新手,请高手指点。谢谢!
目的为了将test文件夹(包含子目录)下的所有特定txt档拷贝到H盘h文件夹下(但子目录不需要拷贝),不考虑文件名相同,找到以下两个脚本,但不知如何合并。见笑了!

代码一:
  1. @echo off
  2. pushd "test"                   ---D:\test
  3. if not exist "h" md "H:\h"
  4. for /f "tokens=* delims=" %%i in ('dir /s /a-d /b *2.txt') do copy "%%i" "H:\h\%%~nxi"
  5. pause
复制代码
代码二:
  1. @echo off
  2. xcopy /ls /d:1-1-2005 "D:\test" "H:\h" /d:1-1-2005 >tmp1
  3. dir /s /a-d /b>tmp2
  4. for /f "delims=" %%a in ('findstr /l /g:tmp1 tmp2') do (
  5.    set "tmp=%%a"
  6.    setlocal enabledelayedexpansion
  7.    copy /y "%%a" "!tmp:~7!"
  8.    endlocal
  9. )
复制代码





欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2