robocopy error return value issues

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Giermo
Posts: 3
Joined: 01 Feb 2013 14:37

robocopy error return value issues

#1 Post by Giermo » 01 Feb 2013 14:46

Hey All
Im just starting with batch scripting, and am having trouble using robocopy. On the first instance of the batch file i run, it works as expected. However on the second instance, it does not. I believe it is caught up at the if error level statement, perhaps due to a uncleared value here from the first run???

Here is what im trying to do.

Code: Select all

::Copy files that are only 1 day old, aka just imported from B2D(exclude files older than 1 days old)
ROBOCOPY C:\B2D_Avante_Diff\ C:\B2D_Avante_Diff_BAK\ /MAXAGE:1


::If copied data sucessfully, move old info to garbage folder, then delete (use files Over 1 day old)
IF ERRORLEVEL 1 ROBOCOPY C:\B2D_Avante_Diff_BAK\ C:\GarbBatchBak\ /MINAGE:1 /MOVE


::Delete all files from the garbage temp folder
::(Q = dont ask for delete confirm)
DEL C:\GarbageBatchBak\ /Q



thanks in advance

Ocalabob
Posts: 79
Joined: 24 Dec 2010 12:16
Location: Micanopy Florida

Re: robocopy error return value issues

#2 Post by Ocalabob » 01 Feb 2013 20:57

Greetings Giermo,

What do mean by "instance"? Do you mean the first time you run the
batch file it works and on the second run it does not work? And are
those runs on the same day?

If the batch is run a second time on the same day then
C:\B2D_Avante_Diff_BAK\ has already been cleared of files over
1 day old thus no files will be moved to C:\GarbBatchBak\
and be deleted since all files in C:\B2D_Avante_Diff_BAK
are only 1 day old.

Maybe I'm missing something here.

Also the errorlevel will be clear once the batch file is complete per your
example.

Best wishes!

(edited to correct typo)

Giermo
Posts: 3
Joined: 01 Feb 2013 14:37

Re: robocopy error return value issues

#3 Post by Giermo » 04 Feb 2013 08:38

First off, thanks for the reply!

By instance i do mean when i run the file. So on the first run it works as expected.

Then before the second run, i create a new txt file for test purposes and place this in the source B2D_Avante_Diff (needing a sucess error code to move on to the error level code line). I then also manually place a week old file into the B2D_Avante_Diff_BAK. Purpose being to see if this file is moved to the garbage on the next run of the batch file. Sure enough, i run the script again and that week old file in B2D_Avante_Diff_BAK stays put versus being moved to garbage as its a week old.

Could this be due to my copy paste of the old file, it thinks its new??? The Date modfied as viewed in explorer stays as the week old date, but upon checking the properties of the file, it has todays create day.

I think this copy is the issue, as the logic seems sound. I must do a run tomorrow, when the date will be expired on its own lol
Is there a way i can manually change the date for testing purposes??

Giermo
Posts: 3
Joined: 01 Feb 2013 14:37

Re: robocopy error return value issues

#4 Post by Giermo » 04 Feb 2013 08:54

WORKS
changed the timestamps with this super easy and nice program
http://www.trickyways.com/2009/08/how-t ... -accessed/

Ocalabob
Posts: 79
Joined: 24 Dec 2010 12:16
Location: Micanopy Florida

Re: robocopy error return value issues

#5 Post by Ocalabob » 04 Feb 2013 10:40

Good thinking and problem solving, Giermo! <Tennis clap> Thank you for reporting back!

Later.

Post Reply