mhn
mhn

Reputation: 2750

Batch file for moving files to specified folder

I need to move files in several different folders into a common folder using a simple batch file

I have a folder called Export into which the files need to go . FileList contains a list of all the files to be moved saved into a text file files.txt. Used the below code but does not work. .

set FIILELIST=C:\List\files.txt
set FILESPATH=C:\
set DESTPATH=C:\Export\

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

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

Upvotes: 0

Views: 2848

Answers (1)

foxidrive
foxidrive

Reputation: 41267

This version caters for the changed filelist - remove the echo after checking.

@echo off
set "FILELIST=C:\List\files.txt"
set "FILESPATH=C:\"
set "DESTPATH=C:\Export\"
for /f "delims=" %%X in (' type "%FILELIST%" ') do echo move "%%X" "%DESTPATH%"
pause

Give this a burl: remove the echo if it does what you want.

@echo off
set "FILELIST=C:\List\files.txt"
set "FILESPATH=C:\"
set "DESTPATH=C:\Export\"

for /f "delims=" %%X in (' type "%FILELIST%" ') do (
for /r "%FILESPATH%" %%I in (%%X) do echo move "%%I" "%DESTPATH%"
)
pause

Upvotes: 1

Related Questions