Batch Moving multiple files with file names within text doc

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
hartland1234
Posts: 3
Joined: 05 Aug 2011 04:03

Batch Moving multiple files with file names within text doc

#1 Post by hartland1234 » 05 Aug 2011 04:18

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.

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Batch Moving multiple files with file names within text

#2 Post by Ed Dyreen » 05 Aug 2011 14:04

Sample.TXT

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
MainBatch.CMD

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
WARNING: UNTESTED !

hartland1234
Posts: 3
Joined: 05 Aug 2011 04:03

Re: Batch Moving multiple files with file names within text

#3 Post by hartland1234 » 08 Aug 2011 02:18

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

Post Reply