0
I have 2 files with 1 containing certain keywords and the other containing a list of paths. I want to search the keywords from the first file list into the list of file paths, and if found then copy the files from the specified file path to a specific target folder.
First File Contents
Keyword1
Keyword2
Keyword3
Keyword4
Second File Contents
\\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
I have to write the Windows batch script for this purpose.
============================================================
Sorry @pimp-juice-it I am not sure how to paste the screenshot. Hence copy-pasting the output below -
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 - Copy (2).txt" d:\Temp_Script\Script>FOR /R "D:\Temp_Script\Source\55 - Copy (2).txt" %G IN (55*) DO ECHO "55" d:\Temp_Script\Script>CALL :FileExist "55" "D:\Temp_Script\Source\55 - Copy.txt"
as you can see the keyword "55" exist in the UNC, but still the condition is not validating to True in the FOR loop and it is going to the next UNC directly. Below is the code -
:FileExist FOR /R "%~2" %%G IN (%~1*) DO ECHO "%~1"
I'd recommend to use something else instead of batch processing. One of those files must be read as many times as a lines count in the second one... PS. Use VBS script, for example... – Akina – 2018-08-07T16:18:45.057