Help with Batch script to move files !!
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.
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.
- simplyeshu
- Posts: 1
- Last visit: Sat Feb 04, 2012 1:24 am
Help with Batch script to move files !!
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
Re: Help with Batch script to move files !!
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%
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%
Re: Help with Batch script to move files !!
Note that backslashes will appear if you use the code block to post scripts.
Also be aware that this post is over one year old and is unlikely to be monitored or needed any more.
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