Hello,
I am new to the forum and I have been reading a lot of comments but I cannot find one to help with my on going problem.
I have a batch file which looks for a string in different text files and then returns the file location. I was just wondering if it was possible to get a batch file to look up a list of file locations within a text file and move them into a certain folder?
I pasted below the filenames that appear in the text file and I basically need a batch file to look up these filenames and then move them to a certain folder.
C:\Users\45645\Desktop\Tests\31474081_0.txt
C:\Users\45645\Desktop\Tests\31474083_0.txt
C:\Users\45645\Desktop\Tests\31474477_0.txt
C:\Users\45645\Desktop\Tests\31475371_0.txt
C:\Users\45645\Desktop\Tests\31476961_0.txt
C:\Users\45645\Desktop\Tests\31476961_1.txt
C:\Users\45645\Desktop\Tests\31482652_0.txt
C:\Users\45645\Desktop\Tests\31506626_0.txt
C:\Users\45645\Desktop\Tests\31508439_0.txt
Thank you if you guys can help. sorry if this is a rubbish question am not very good at batches at all.
Batch Moving multiple files with file names within text doc
Moderator: DosItHelp
-
- Posts: 3
- Joined: 05 Aug 2011 04:03
Re: Batch Moving multiple files with file names within text
Sample.TXT
MainBatch.CMD
WARNING: UNTESTED !
Code: Select all
C:\Users\45645\Desktop\Tests\31474081_0.txt
C:\Users\45645\Desktop\Tests\31474083_0.txt
C:\Users\45645\Desktop\Tests\31474477_0.txt
C:\Users\45645\Desktop\Tests\31475371_0.txt
C:\Users\45645\Desktop\Tests\31476961_0.txt
C:\Users\45645\Desktop\Tests\31476961_1.txt
C:\Users\45645\Desktop\Tests\31482652_0.txt
C:\Users\45645\Desktop\Tests\31506626_0.txt
C:\Users\45645\Desktop\Tests\31508439_0.txt
Code: Select all
@echo off &SetLocal EnableExtensions EnableDelayedExpansion
set "$NewLocation.FullPath=C:\Windows\Temp"
for /f "usebackq tokens=*" %%! in (
"Sample.TXT"
) do if exist "%%~!" (
::
for %%r in ( "%%~!" ) do set "$File=%%~nxr"
::
copy /y "%%~!" "!$NewLocation.FullPath!\!$File!"
)
EndLocal
-
- Posts: 3
- Joined: 05 Aug 2011 04:03
Re: Batch Moving multiple files with file names within text
Hello,
Thank you very much for that, I was just wondering if possible you might be able to explain the different bits below? just so I can maybe try and get a better understanding?
@echo off &SetLocal EnableExtensions EnableDelayedExpansion
set "$NewLocation.FullPath=C:\Windows\Temp"
for /f "usebackq tokens=*" %%! in (
"Sample.TXT"
) do if exist "%%~!" (
::
for %%r in ( "%%~!" ) do set "$File=%%~nxr"
::
copy /y "%%~!" "!$NewLocation.FullPath!\!$File!"
)
EndLocal
Thank you very much for that, I was just wondering if possible you might be able to explain the different bits below? just so I can maybe try and get a better understanding?
@echo off &SetLocal EnableExtensions EnableDelayedExpansion
set "$NewLocation.FullPath=C:\Windows\Temp"
for /f "usebackq tokens=*" %%! in (
"Sample.TXT"
) do if exist "%%~!" (
::
for %%r in ( "%%~!" ) do set "$File=%%~nxr"
::
copy /y "%%~!" "!$NewLocation.FullPath!\!$File!"
)
EndLocal