更新时间:2023-01-30 22:00:38
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET "DEST_DIR=%USERPROFILE%\Desktop\Folder"
SET "SEARCH_DIR=S:\Class"
FOR /F "tokens=*" %%a IN ('type %~dp0list.txt') DO (
FOR /R "%SEARCH_DIR%" %%f IN (*%%a*) DO (
SET "SRC=%%~dpf"
SET DEST=!SRC:%SEARCH_DIR%=%DEST_DIR%!
xcopy /S /I "%%~f" "!DEST!"
)
)
这是您发布的脚本中一行(FOR循环)的修改.
This is a modification of a single line (the FOR loop) in the script you posted.
list.txt
中的每一行进行递归搜索.这效率低下,但是如果您想提高效率,则可能不会使用纯批处理/CMD.*<pattern>*
完成,其中< pattern>是list.txt
中的完整行.tokens=*
:不管分隔符如何,都将每一行上的所有文本捕获为变量的内容. (这实际上与"delims="
相同.)/S
:请勿处理(或创建)空目录SRC
用于允许替换以构建目标路径(它是目录,而不是文件名-xcopy是为目录设计的).list.txt
. This is inefficient, but if you wanted efficiency, you probably wouldn't be using pure batch/CMD.*<pattern>*
, where <pattern> is a complete line in list.txt
.tokens=*
: Regardless of delimiter, capture all text on each line as the content of the variable. (This is effectively the same as "delims="
.)/S
: don't process (or create) empty directoriesSRC
is used to allow substitution to build a destination path (which is a directory, not a file name—xcopy is designed for directories).list.txt :
micro
pipeline
exhaust