Need immediate help with a batch script

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
rbharti
Posts: 6
Joined: 24 Apr 2012 03:00

Need immediate help with a batch script

#1 Post by rbharti » 24 Apr 2012 03:36

I am new to batch script.. Requirement is like this..

> Read the file content (it has list of file names)
> find all those files from above step in a folder A
> then move those files to folder B

Kindly please help on how I can do this using batch script.

jeb
Expert
Posts: 1062
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

Re: Need immediate help with a batch script

#2 Post by jeb » 24 Apr 2012 04:39

If you need immediately help, Google is your friend!

What do you tried?

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Need immediate help with a batch script

#3 Post by Squashman » 24 Apr 2012 05:45

http://ss64.com/nt/for_f.html
http://ss64.com/nt/dir.html
http://ss64.com/nt/move.html

rbharti
Posts: 6
Joined: 24 Apr 2012 03:00

Re: Need immediate help with a batch script

#4 Post by rbharti » 24 Apr 2012 06:09

Thx squashman. Trying to understand and prepare a script but not sure how far I will go.

Is there anyone who can write up in batch script format.

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Need immediate help with a batch script

#5 Post by Squashman » 24 Apr 2012 06:18

untested

Code: Select all

@echo off
FOR /F "usebackq delims=" %%G in ("filelist.txt") do (
     IF EXIST "C:\Folder A\%%G" MOVE "C:\Folder A\%%G" "C:\Folder B\%%G"
)

rbharti
Posts: 6
Joined: 24 Apr 2012 03:00

Re: Need immediate help with a batch script

#6 Post by rbharti » 24 Apr 2012 08:04

Squashman, No it din't work

I have modified like this and tried but it didn't do anything
I had one file in raj1 folder and listed that file name in filelist.txt. Created raj2 folder and ran the script but failed.

@echo off
FOR /F "usebackq delims=" %%G in ("filelist.txt") do (
IF EXIST "C:\raj1 A\%%G" MOVE "C:\raj1 A\%%G" "C:\raj2 B\%%G"
)

rbharti
Posts: 6
Joined: 24 Apr 2012 03:00

Re: Need immediate help with a batch script

#7 Post by rbharti » 24 Apr 2012 08:19

looks like it's looking for some sort of command to read the content of filelist.txt.

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Need immediate help with a batch script

#8 Post by Squashman » 24 Apr 2012 08:40

If there is an error message you need to post the exact error message you are seeing.

rbharti
Posts: 6
Joined: 24 Apr 2012 03:00

Re: Need immediate help with a batch script

#9 Post by rbharti » 24 Apr 2012 09:11

No error on the screen but it's not doing anything either.

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Need immediate help with a batch script

#10 Post by Squashman » 24 Apr 2012 09:34

Can I see an example of the contents of your File List.

rbharti
Posts: 6
Joined: 24 Apr 2012 03:00

Re: Need immediate help with a batch script

#11 Post by rbharti » 24 Apr 2012 10:26

these are the files that's in raj1 folder and same I have listed in filelist.txt. I also putting backslash in front of raj1 and raj2 but it didn't help.

*filelist.txt
RajnishBharti9YSS9G84ML64622.pdf
role.txt
sizing.rtf
*raj1 folder has above three physical files
* raj2 folder is empty
* script.bat looks like this now
@echo off
FOR /F "usebackq delims=" %%G IN ("C:\Users\rbharti\Desktop\archival\filelist.txt") do (
IF EXIST "C:\Users\rbharti\Desktop\archival\raj1\ A\%%G"
move "C:\Users\rbharti\Desktop\archival\raj1\ A\%%G", "C:\Users\rbharti\Desktop\archival\raj2\ B\%%G"
)

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Need immediate help with a batch script

#12 Post by Squashman » 24 Apr 2012 10:35

1) That whole IF EXIST statement needs to be on one line. If it is not on one line then you need to use parenthesis to continue the code block.
2) You have a comma in the middle of the move statement. Why?
3) Is that how your directory structure is? You have a space before your Folder A and Folder B.

Code: Select all

@echo off
FOR /F "usebackq delims=" %%G IN ("C:\Users\rbharti\Desktop\archival\filelist.txt") do (
IF EXIST "C:\Users\rbharti\Desktop\archival\raj1\ A\%%G" move "C:\Users\rbharti\Desktop\archival\raj1\ A\%%G" "C:\Users\rbharti\Desktop\archival\raj2\ B\%%G"
)

Post Reply