您的位置:首页 > 其它

批处理查找并复制文件到指定文件夹

2017-05-07 00:07 295 查看
        如何通过批处理,在一个目录及其子目录中查找指定列表中的所有文件,并把这些文件复制到指定的文件夹中呢?下面这个批处理可堪一用:

********************START*******************************

@echo off

setlocal enabledelayedexpansion

rem set parameter here

set sourcePath=E:\Test\source

set targetPath=E:\Test\target

set fileList=list.txt

set /a copyCount=0

dir /s /b !sourcePath!>filelist.txt

for /f "delims=" %%i in (!fileList!) do (

find "%%i" filelist.txt > findfile.txt

if !errorlevel! equ 0 (

for /f "skip=2 delims=" %%j in (findfile.txt) do (

copy /y %%j !targetPath!\%%i>nul

set /a copyCount+=1

)

)else (

echo can't find file %%i

)

)

del filelist.txt

del findfile.txt

echo ************************************

echo copy file success: !copyCount!

pause

********************END*******************************

        sourcePath是查找的文件夹,targetPath是目标文件夹,fileList是所有的待查找文件列表,是一个文本文件,格式如下:

光辉岁月.txt
江南.txt
123.mp3


        执行完毕后会得到类似的结果,找不到的文件给出文件名,然后给出复制了多少个文件的结果:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息