Batch Script to find a files inside all Sub Folders -


i have multiple images in sub folder, don't know how many folders there. want batch script find listed names in folders , copy images destination folder. tried below script getting file not found error.

@echo off  rem find files , copy files  setlocal enableextensions enabledelayedexpansion  set "sourcebasefolder=d:\system backup\picture batch file\test\15oct2015" set "targetbasefolder=c:\outputfolder"  if not exist "%sourcebasefolder%\*" (     echo %~nx0: there no folder %sourcebasefolder%     set "errorcount=1"     goto haltonerror )  cd /d "%sourcebasefolder%"  if not exist "filenames.txt" (     echo %~nx0: there no file %sourcebasefolder%\filenames.txt     set "errorcount=1"     goto haltonerror )  set "errorcount=0" /f "usebackq delims=" %%n in ("filenames.txt") (     /r %%j in ("%%n*") (         set "filepath=%%~dpj"         if "!filepath:%targetbasefolder%=!" == "!filepath!" (             set "targetpath=%targetbasefolder%\!filepath:%sourcebasefolder%\=!"             md "!targetpath!" 2>nul             if exist "!targetpath!\*" (                 echo copying file %%~fj                 copy /y "%%~fj" "!targetpath!" >nul             ) else (                 set /a errorcount+=1                 echo failed create directory !targetpath!             )         )     ) )  :haltonerror if %errorcount% neq 0 (     echo.     pause ) endlocal 

can 1 fix problem? in advance.

the solution you're trying work seems excessively convoluted

i believe similar following should want

for /f %%g in ('dir /a-d /s /b "d:\system backup\picture batch file\test\15oct2015"^|findstr /i /e /g:"d:\system backup\picture batch file\test\15oct2015\filenames.txt"') ( copy "%%g" "c:\outputfolder" ) 

to ensure filename matches exact, filenames in filenames.txt should preceded backslash, e.g.

\filename1.file \filename2.file 

you can generate such file within batch file, if necessary


Comments

Popular posts from this blog

php - Cannot override Laravel Spark authentication with own implementation -

Qt QGraphicsScene is not accessable from QGraphicsView (on Qt 5.6.1) -

What is happening when Matlab is starting a "parallel pool"? -