3

I have a Master folder which have multiple sub folders. All the subfolders have lot images with different extensions (jpg,tif and png). The total number of images in all the subfolder are around 90000 images.

The thing is, I need to search some 500 images in Master folder and its subfolders and move the images to specified folder.

I tried a below batch script to use the text file to search through a Master folder and all subfolders and move all the files from the list and paste them into a Specified single folder. The text file which contains file names without extension. But my batch script is not working. It didnt throw me any error.. but nothing happens when I run it.

set FIILELIST=C:\padhu\files.txt
set FILESPATH=C:\Padhu\MasterFolder
set DESTPATH=C:\DestinationFolder

for /f %%X in (%FIILELIST%) do call :MOVE_FILES "%%X"
goto :eof

:MOVE_FILES
for /r %FILESPATH% %%I in (%~1) do echo move /qvs "%%I" "%DESTPATH%%%~pnxI"

I am very new to batch script and in learning stage. Kindly help me in this. Im very much thankful if anyone provide the correct batch script to do this.

sparker
  • 1,666
  • 4
  • 21
  • 35

2 Answers2

8

Can you try this?

set FIILELIST=C:\padhu\files.txt
set FILESPATH=C:\Padhu\MasterFolder
set DESTPATH=C:\DestinationFolder

for /f "delims=" %%x in (%FIILELIST%) do (forfiles /p %FILESPATH% /s /m %%x.* /c "cmd /c move /y @path %DESTPATH%\@file" 2>>failed_temp.txt)
for /f "tokens=5 " %i in (failed_temp.txt) do (echo.%~i)>>failed_list.txt
del failed_temp.txt

Cheers, G

gbabu
  • 1,088
  • 11
  • 15
  • Thanks, Works great. Can we get the list of files in the text file which are not found in the Master folder and its subs? – sparker Aug 15 '14 at 11:27
  • That will require some additional coding, but when you run the above code, if the file is not found it will print the message `ERROR: Files of type "filename" not found.` from which you can find the files that are not found. – gbabu Aug 15 '14 at 11:31
  • Is there any command to get the all error messages in the text file while running the batch.? – sparker Aug 15 '14 at 14:56
  • Added the ability to capture the failure now. not found list should now be stored in `failed_list.txt` – gbabu Aug 15 '14 at 15:07
3

@gbabu's answer was super helpful for me.

I needed to edit it to handle file names that were absolute (full) instead of relative. And I needed to handle that they contained spaces.

Unfortunately I couldn't figure out how to log the errors like @gbabu did.

@echo off
REM See https://stackoverflow.com/a/25325529/470749
REM See https://stackoverflow.com/a/163873/470749
REM See https://stackoverflow.com/a/155950/470749
set FILELIST="K:\F\Users\my_user\Documents\My Music\JUKEBOX\5.m3u_list.txt"
set DESTPATH=C:\temp\cdrw
for /f "usebackq tokens=*" %%x in (%FILELIST%) do (copy "%%x" %DESTPATH%)
pause

These articles helped me:

Ryan
  • 22,332
  • 31
  • 176
  • 357