Here is another approach to search without using the command WHERE
Just give a try and tell me the results !
@echo off
Title Searching for a specific file name and copy them to a new location
Mode con cols=90 lines=30 & color 9E
set "FailedLog=%~dp0failed1.txt"
set "ConvertedFile=%~dp0Converted.txt"
set "OutPutFile=%~dp0OutPutFile.txt"
set "List=%~dp0%~n0_List.txt"
set "FoundFile=%~dp0%~n0FoundFile.txt"
set "SourceLocation=D:\"
set "Destination=F:\LostImage"
If not exist "%Destination%" MD "%Destination%"
If Exist "%OutPutFile%" Del "%OutPutFile%"
If Exist "%List%" Del "%List%"
If Exist "%FoundFile%" Del "%FoundFile%"
Cls
echo(
echo --------------------------------------------------------------------------
echo Please Wait a while ....... Searching is in progress .........
echo --------------------------------------------------------------------------
set Count=0
Set "Tmpvbs=%tmp%\%~n0.vbs"
(
echo Data = WScript.StdIn.ReadAll
echo Data = ReplaceString(Data^)
echo WScript.StdOut.WriteLine Data
echo '************************************************
echo Function ReplaceString(Data^)
echo Data = Replace(Data,ChrW(8220^),ChrW(34^)^)
echo Data = Replace(Data,ChrW(8221^),ChrW(34^)^)
echo ReplaceString = Data
echo End Function
echo '************************************************
)>"%Tmpvbs%"
Rem We replace the unicode double quotes Left [ChrW(8220)] and Right [ChrW(8221)] by,
Rem a simple double quote [ChrW(34)], and we save it
Rem into a file called Converted.txt
Call :ReplaceString %FailedLog% %ConvertedFile%
setlocal ENABLEDELAYEDEXPANSION
for /f "tokens=5 delims= " %%a in ('Type "%ConvertedFile%"') do (
Set /a Count+=1
Set "FileName[!Count!]=%%a"
)
Rem We create a list file with extension jpg png gif
Set "Ext=jpg png gif"
for %%E in (%Ext%) do (
Dir /A-D /b /s "%SourceLocation%*.%%E"
)>> "%List%"
for /L %%i in (1,1,%Count%) do (
for /f "delims=" %%f in ('Type "%List%" ^|find /I !FileName[%%i]!') do (
if "%errorlevel%" EQU "0" (
@echo "%%f"
@echo "%%f" >> "%FoundFile%"
@copy /y "%%f" "%Destination%"
)
)
)
Start "" "%FoundFile%" & pause & exit
::*****************************************
:ReplaceString <InputData> <OutPutData>
cscript /nologo "%Tmpvbs%" < "%~1" > "%~2"
If Exist "%Tmpvbs%" Del "%Tmpvbs%"
exit /b
::*****************************************