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.
This topic is 11 years and 1 week old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
simplyeshu
Posts: 1
Last visit: Sat Feb 04, 2012 1:24 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
NetGod1
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%
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 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.
This topic is 11 years and 1 week old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked