Support Forums

Help with Batch script to move files !!

Batch, ASP, JScript, Kixtart, etc.
Forum rules
Do not post any licensing information in this forum.
User avatar
Posts: 1
Joined: Sat Feb 04, 2012 2:22 am

Help with Batch script to move files !!

Postby simplyeshu » Sat Feb 04, 2012 2:24 am

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.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
User avatar
Posts: 1
Joined: Tue Mar 05, 2013 11:21 pm

Re: Help with Batch script to move files !!

Postby NetGod1 » Tue Mar 05, 2013 11:44 pm

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%
User avatar
Posts: 10948
Joined: Tue May 22, 2007 9:57 am

Re: Help with Batch script to move files !!

Postby jvierra » Wed Mar 06, 2013 2:28 am

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.

Return to “Other Scripting Languages”

Who is online

Users browsing this forum: No registered users and 1 guest