XCopy - zero files affected failure

Hi.

How can i fail the XCopy action if no files were copied?

Thanks,
NirS

Hi NirS,

If you specify an exact file name for XCopy, eg. “MyFile.txt” then XCopy will return a non-zero return code and will fail the action. Unfortunately, it doesn’t return a non-zero return code if you use any type of wildcard.

So… this is how you can get XCopy to fail if 0 files found.

1. Add an FB variable called “FailXCopy” (without the quotes), set it’s default value to False
2. In the BeforeAction script event for your XCopy put this VBScript code:
FailXCopy = False
3. In the AfterAction put this:
if ActionResult = True then
if FailXCopy = True then
ActionResult = False
Continue = False
Action.SendLogMessage “Failing action because no files copied”
end if
end if
4. In the OnStatusMessage put this:
if InStr(1,StatusMessage.MessageText,“0 File(s) copied”,1) > 0 then
FailXCopy = True
end if

that’s it… hth!

.t8

Thanks very much Tate, it helps a lot!