Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
gussy81
- Posts: 3
- Joined: 16 Jul 2019 08:56
#1
Post
by gussy81 » 04 Apr 2024 08:51
OK so i have a script working for me. It mirrors one directory to the other and going forward it only mirrors files that have changed. I now want it to tell me if it has run successfully or not in the log as i want to run it out of hours daily:
Code: Select all
robocopy F:\ B:\ /e /mir /z /FFT /R:3 /W:5
Echo My Daily Backup Logged time = %time% %date%>>H:\log-of-daily-robocopy.txt
Thanks for any help
G
-
Sponge Belly
- Posts: 231
- Joined: 01 Oct 2012 13:32
- Location: Ireland
-
Contact:
#2
Post
by Sponge Belly » 08 Apr 2024 08:34
Hi Gussy!
If a command executes successfully, it sets errorLevel to 0, a non-zero integer otherwise. There’s an easy way to test for this and to take appropriate action. The syntax goes a little something like this:
Code: Select all
command && (
success
) || (
failure
)
So, your code example would be rewritten as:
Code: Select all
2>nul robocopy F:\ B:\ /e /mir /z /FFT /R:3 /W:5 && (
Echo(My Daily Backup Logged time = %time% %date%>>H:\log-of-daily-robocopy.txt
) || (
Echo(Something went wrong with the robocopy backup!
)
I hope this answers your question. If you have any follow-up questions, please feel free to ask.
- SB
-
Sponge Belly
- Posts: 231
- Joined: 01 Oct 2012 13:32
- Location: Ireland
-
Contact:
#4
Post
by Sponge Belly » 08 Apr 2024 13:34
Hi Squashman!
I didn’t know that about robocopy. Good to know, thanks!
Gussy, don’t use the "command && success || failure" syntax with robocopy. Follow the example on the SS64 web page referenced by Squashman. Make sure you start with the highest errorLevel and work your way down to the lowest.
Good luck!
- SB