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.

bjcyber

Distinguished
Jun 8, 2012
105
0
18,690


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

bjcyber

Distinguished
Jun 8, 2012
105
0
18,690


is there are any good site to learn those things
 

bjcyber

Distinguished
Jun 8, 2012
105
0
18,690


thanks..
 

bjcyber

Distinguished
Jun 8, 2012
105
0
18,690
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...
 

chugot9218

Honorable
Sorry was out of the area this weekend, is that the actual line you used? If so, you have a space after the last \ in your source. Otherwise, it may be too old an OS to support wild cards. If you still need help post back.
 

bjcyber

Distinguished
Jun 8, 2012
105
0
18,690


really need help... i will trying removing the space, and then i get back to you...
 

chugot9218

Honorable
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.
 

bjcyber

Distinguished
Jun 8, 2012
105
0
18,690


Its working.. thank you so much... can you please tell me how to add log report for this.. please...
 

chugot9218

Honorable
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.
 

bjcyber

Distinguished
Jun 8, 2012
105
0
18,690


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...