Help with Batch script to move files !!

Batch, ASP, JScript, Kixtart, etc.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
User avatar
Posts: 1
Last visit: Sat Feb 04, 2012 1:22 am

Help with Batch script to move files !!

Post by simplyeshu »

I have written a small batch script to move the files from two directories to one main directory. It should record all the activities in a log file like files have been moved successfully from directory b to directory A and total number of files moved along with timestamp but its not working. Can you please review and help? Appreciate your help. Also tell me if we can automate this to run everyday at particular time (between 10pm - 11pm)echo "files moving at "%date%-%time%" >> c:OutputFile.logmove "C:A*.*" "C:Test" >> C:OutputFile.logmove "C:B*.*" "C:Test" >> C:OutputFile.logecho "files moved at "%date%-%time%" >> c:outputfile.log

User avatar
Posts: 1
Last visit: Tue Mar 12, 2013 4:20 pm

Re: Help with Batch script to move files !!

Post by NetGod1 »

EDIT: I noticed that backslashes do not show up in the posts. Odd. Make sure there is a backslash after every "C:" and after "Adir" and "Bdir" (of course, use your directory names)

At the command line you must denote directories by using backslashes. Otherwise the command processor thinks they are file names. Also, you have a lot of quotes that you don't need. ECHO does exactly that, ECHOs characters, spaces, everything - even the quotes. Unless you specifically want the quotes in your log file, leave them out. IMO, it just makes the log file busy & harder to read. Also, I've created a variable for the log file name. This makes it much easier if you want to change the log file name later. You only need to change it once instead of four times.

To run it every day at a certain time, you will have to use Task Scheduler to execute it at your desired time.

This will move all files from C:\Adir and C:\Bdir to C:\Test and create a log file on the root of C:\ drive.

Try this:

set LogFile=C:\OutputFile.log

echo files moving at %date%-%time% >> %LogFile%
move "C:\Adir\*.*" "C:\Test" >> %LogFile%
move "C:\Bdir\*.*" "C:\Test" >> %LogFile%
echo files moved at %date%-%time% >> %LogFile%

Posts: 14950
Last visit: Sat Oct 16, 2021 3:09 pm
Answers: 14
Has voted: 3 times
Been upvoted: 11 times

Re: Help with Batch script to move files !!

Post by jvierra »

Note that backslashes will appear if you use the code block to post scripts.

Code: Select all

echo "files moving at "%date%-%time%" >> c:\OutputFile.log
move C:\A*.* C:\Test >> C:OutputFile.log
move C:\B*.* C:\Test >> C:OutputFile.log
echo "files moved at "%date%-%time%" >> c:\outputfile.log

Also be aware that this post is over one year old and is unlikely to be monitored or needed any more.