Batch file to move many listed files to one specific folder

て烟熏妆下的殇ゞ 提交于 2020-08-02 04:53:32

问题


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.


回答1:


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




回答2:


@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:

  • https://stackoverflow.com/a/25325529/470749
  • https://stackoverflow.com/a/163873/470749
  • https://stackoverflow.com/a/155950/470749


来源:https://stackoverflow.com/questions/25325123/batch-file-to-move-many-listed-files-to-one-specific-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!