cmd script for moving rar files to another directory.

bjcyber

Distinguished
Jun 8, 2012
105
0
18,690
i have ERP system running on server 2003. it create daily backups on desktop. (.RAR files). so i want to move those rar files which is older than 1 day to my E drive.
please help.
 
Solution
Use Robocopy: http://ss64.com/nt/robocopy.html ROBOCOPY Source_folder Destination_folder [files_to_copy] [options]

sooo ROBOCOPY c:\folder e:\folder *.rar /MINAGE:1

save it as a .bat file and schedule it to run once a day, you can add the /MOV option if you want to delete the files from the source directory.


thank you so much... i"ll check this and get back.
 


is there are any good site to learn those things
 


thanks..
 
can't use robocopy cuz i'm using server 2003. so i created xcopy command below.

xcopy c:\documents and settings\asministrator\desktop\ *.rar E:\daily backup\

but it won't work... it says invalid parameter...
 


really need help... i will trying removing the space, and then i get back to you...
 
Ooops, also you need to contain it in "'s, this should be the proper one (I assume you mis-typed the administrator portion).

xcopy "c:\documents and settings\administrator\desktop\*.rar" "E:\daily backup\"

That should do it for you.
 


Its working.. thank you so much... can you please tell me how to add log report for this.. please...
 
I am learning new stuff myself helping you. Try this:

ECHO.| DATE >> "E:\daily backup\backuplog.txt"
xcopy "c:\documents and settings\administrator\desktop\*.rar" "E:\daily backup\" >> "E:\daily backup\backuplog.txt"

This may give you strange results though if you are prompted by XCopy, for example, I did not specify that xcopy should automatically overwrite a file, so when it prompted me with Overwrite C:\ROBOCOPYtest\test.txt (Yes/No/All)? that text was automatically written to the log file instead of displayed in the command console which can be somewhat confusing.

If you will never have to worry about overwrites, then you are good to go with these two lines. Otherwise you could append the option to XCOPY to overwrite without prompt if that's what you desire, in which case it would look like this:

ECHO.| DATE >> "E:\daily backup\backuplog.txt"
xcopy "c:\documents and settings\administrator\desktop\*.rar" "E:\daily backup\" >> "E:\daily backup\backuplog.txt" /Y

Careful that you don't run into access issues or the .bat can go into an infinite loop, in Win7 I had to run it as administrator.
 


i will try this..but before that i have run in to problem.. when the script run it always ask to overright ... i have to type "N" always. otherwise it won't copy. is there any way to write this in script. I want it to not overwright exsisting file when copying... thanks...