하나는 특정 키워드를 포함하고 다른 하나는 경로 목록을 포함하는 2개의 파일이 있습니다. 첫 번째 파일 목록의 키워드를 파일 경로 목록으로 검색하고, 발견되면 지정된 파일 경로의 파일을 특정 대상 폴더로 복사하고 싶습니다.
첫 번째 파일 내용
Keyword1
Keyword2
Keyword3
Keyword4
두 번째 파일 내용
\\server\path...\Keyword1.txt
\\server\path...\Keyword1_0_1.txt
\\server\path...\Keyword2_0_1.txt
\\server\path...\Keyword2_1_9.txt
\\server\path...\Keyword3_1_0_1.txt
이 목적을 위해 Windows 배치 스크립트를 작성해야 합니다.
================================================= ==========
죄송합니다 @pimp-juice-it 스크린샷을 어떻게 붙여넣어야 할지 모르겠습니다. 따라서 아래 출력을 복사하여 붙여넣습니다.
d:\Temp_Script\Script>FOR /R "D:\Temp_Script\Source\33.txt" %G IN (55*) DO ECHO "55" d:\Temp_Script\Script>CALL :FileExist "55" "D: \Temp_Script\Source\44.txt" d:\Temp_Script\Script>FOR /R "D:\Temp_Script\Source\44.txt" %G IN (55*) DO ECHO "55" d:\Temp_Script\Script> CALL :FileExist "55" "D:\Temp_Script\Source\55.txt" d:\Temp_Script\Script>FOR /R "D:\Temp_Script\Source\55.txt" %G IN (55*) DO ECHO " 55" d:\Temp_Script\Script>CALL :FileExist "55" "D:\Temp_Script\Source\55 - 복사 (2).txt" d:\Temp_Script\Script>FOR /R "D:\Temp_Script\Source\ 55 - 복사 (2).txt" %G IN (55*) DO ECHO "55" d:\Temp_Script\Script>CALL :FileExist "55" "D:\Temp_Script\Source\55 - Copy.txt"
보시다시피 키워드 "55"가 UNC에 존재하지만 여전히 FOR 루프에서 조건이 True인지 확인하지 않고 다음 UNC로 직접 이동합니다. 아래는 코드입니다 -
:FileExist FOR /R "%~2" %%G IN (%~1*) 에코 "%~1" 실행
답변1
"키워드" 목록을 한 번 반복하고 포함된 일부 와일드카드 문자와 함께 반복된 키워드 값을 검색 문자열로 사용할 수 있습니다.즉 *<Keyword>*
. 파일 목록에서 각 UNC 경로 값의 디렉터리 트리를 탐색하고 검색 문자열 "키워드"와 일치하는 항목에만 복사 작업을 수행할 수 있습니다.
그래도 본질적으로...
배치 스크립트
@ECHO ON
SET "strList=\\server\Folder\Path\SearchStrings.txt"
SET "pathList=\\server\Folder\Path\UNCPaths.txt"
SET "targetPath=\\server\target\folder\path"
FOR /F "USEBACKQ TOKENS=*" %%S IN ("%strList%") DO CALL :Paths "%%~S"
PAUSE
EXIT
:Paths
FOR /F "USEBACKQ TOKENS=*" %%P IN ("%pathList%") DO CALL :FileExist "%~1" "%%~P"
GOTO :EOF
:FileExist
FOR /R "%~2" %%C IN (*%~1*) DO XCOPY /F /Y "%%~C" "%targetPath%\"
GOTO :EOF
추가 리소스
-
CALL 명령은 지정된 매개변수와 함께 지정된 레이블 뒤의 명령문에 제어를 전달합니다. 서브루틴을 종료하려면
GOTO:eof
현재 서브루틴의 끝으로 제어가 전송되도록 지정하십시오. -
FOR /R [[drive:]path] %variable IN (set) DO command [command-parameters] Walks the directory tree rooted at [drive:]path, executing the FOR statement in each directory of the tree. If no directory specification is specified after /R then the current directory is assumed. If set is just a single period (.) character then it will just enumerate the directory tree.