- @echo off
- set "FileTxt=D:\a.txt"
- set "SourDir=D:\Test"
- set "DestDir=D:\Test1"
- cd /d "%SourDir%"
- for /f %%a in ('type "%FileTxt%"') do (
- for /f %%i in ('dir /a-d /b /s^|findstr "%%a"') do (
- set "DirName=%%~dpi"
- setlocal enabledelayedexpansion
- set "DirName=!DirName:%SourDir%=!"
- if not exist "%DestDir%!DirName!" md "%DestDir%!DirName!"
- copy "%%i" "%DestDir%!DirName!"
- endlocal
-
- ))
- pause
复制代码 根据a.txt中所列文件名,查找源目录D:\Test,如果文件存在,复制到目的目录D:\Test1中,并保存文件原来的文件夹结构。 |