Move command question

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
ED209
Posts: 8
Joined: 07 Jul 2011 12:17

Move command question

#1 Post by ED209 » 07 Jul 2011 12:27

Hi all,

I'm wondering is it possible to do a dos move using an input file.. I've 400+ files to move from one dir to another and thought it might be a bit cleaner if I could use a txt file as the input but not sure if thats possible..

Any help would be appreciated..

Thanks...

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Move command question

#2 Post by aGerman » 07 Jul 2011 12:32

How does your list look like? Only the source file names line by line?

Regards
aGerman

ED209
Posts: 8
Joined: 07 Jul 2011 12:17

Re: Move command question

#3 Post by ED209 » 07 Jul 2011 12:44

Hi,

At the minute it's just in a txt file in the following format:

About.bmp
ACTDATA.CSV
APPTRACK.EXE
ARA_FIHI.CSV


and so on...

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Move command question

#4 Post by aGerman » 07 Jul 2011 12:54

Untested:

Code: Select all

@echo off &setlocal
set "sourceFolder=c:\path\to\your\files"
set "destinationFolder=c:\path\to\move\the\files"
set "listFile=myFileList.txt"

for /f "usebackq delims=" %%a in ("%listFile%") do (
  move "%sourceFolder%\%%~a" "%destinationFolder%\"
)

Regards
aGerman

ED209
Posts: 8
Joined: 07 Jul 2011 12:17

Re: Move command question

#5 Post by ED209 » 07 Jul 2011 13:12

Just did a quick test and it works great..

Thanks a mil for your help..

EDIT**
Actually, would you mind explaining what the below is doing?

Code: Select all

usebackq delims=" %%a in

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Move command question

#6 Post by aGerman » 07 Jul 2011 13:54

Of ourse.
The FOR /F loop iterates the list file line by line.
I used USEBACKQ for being able to enclose the file name in double quotes (that was done because I didn't know whether the file name of your list contains spaces).
Normally the line read from the list would be delimited in tokens by spaces and tabs. For that reason I used DELIMS= to disable the default delimiters and make sure you get the entire line into variable %%a.

Have a look at the command index to learn more.

Regards
aGerman

ED209
Posts: 8
Joined: 07 Jul 2011 12:17

Re: Move command question

#7 Post by ED209 » 07 Jul 2011 13:57

Cool, thanks again.. I'll have a read up on the command index now..

Ed Diarrhea
Posts: 6
Joined: 01 Jul 2011 16:38

Re: Move command question

#8 Post by Ed Diarrhea » 07 Jul 2011 16:17

ED209 wrote:!?!command index!?!

Post Reply