[英]Batch file to search directory for list of files and copy to single folder
I have a .txt file with a list of files that are on a network drive (M:). 我有一个.txt文件,其中包含网络驱动器(M :)上的文件列表。 I need a batch file to go through that list, search for the files which are in sub-directories of a single folder on that drive, and then copy them to another folder.
我需要一个批处理文件来浏览该列表,搜索该驱动器上单个文件夹的子目录中的文件,然后将它们复制到另一个文件夹。 I have tried quite a few solutions with no luck.
我已经尝试了很多解决方案,但都没有运气。
the text file is a list of files and extensions ie 文本文件是文件和扩展名的列表,即
abc.step
afer.iges
ca76dc7d.sldprt
Here's what I tried so far 到目前为止,这是我尝试过的
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
cls
set dest=C:\Users\kduquette.000\Desktop\Files
for /f "TOKENS=*" %%f in (C:Desktop\Files\list.txt) do (
set i=1
for /f "tokens=*" %%F IN ('dir M: "%%~f"') Do (
for %%N in ("%%F") Do (
set name=%%~NN
set ext=%%~XN
)
copy "%%~F" "%dest%\!name!_!i!!ext!"
set /A i=!i!+1
)
)
ENDLOCAL
We can just do a check if file exists and copy it: 我们可以检查文件是否存在并复制它:
@echo off
set "dest=C:\Users\kduquette.000\Desktop\Files"
for /f "delims=" %%i in (C:\Desktop\Files\list.txt) do if exist "M:\Cads\%%i" echo copy "M:\Cads\%%i" "%dest%"
Note, for now, I added echo
to the copy string, so you can test the result first. 注意,目前,我在复制字符串中添加了
echo
,因此您可以首先测试结果。 Once happy with the results, remove echo
对结果满意后,请删除
echo
If however you want to search for the files, recursively throughout M:\\
drive then: 但是,如果要搜索文件,请在
M:\\
驱动器中递归搜索,然后:
@echo off
set "dest=C:\Users\kduquette.000\Desktop\Files"
for /f "delims=" %%i in (C:\Desktop\Files\list.txt) do (
pushd M:\
for /f "delims=" %%a in ('dir /b /s "%%i"') do echo copy "%%~fa" "%dest%"
popd
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.