# XCopy - zero files affected failure

**URL:** https://www.finalbuilder.com/forums/t/xcopy-zero-files-affected-failure/93
**Category:** Discussion
**Created:** [May 16, 2006, 3:23am UTC](https://www.finalbuilder.com/forums/t/xcopy-zero-files-affected-failure/93 "2006-05-16T03:23:17Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![nirsilgi](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/n/a6a055/32.png) [@nirsilgi](https://www.finalbuilder.com/forums/u/nirsilgi)
#### Post date: [May 16, 2006, 3:23am UTC](https://www.finalbuilder.com/forums/t/xcopy-zero-files-affected-failure/93/1 "2006-05-16T03:23:17Z")

</div>

Hi.  
  
How can i fail the XCopy action if no files were copied?  
  
Thanks,  
NirS

---

<div class="post-metadata">

### Author: ![tate](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/t/e19b73/32.png) [@tate](https://www.finalbuilder.com/forums/u/tate)
#### Post date: [May 17, 2006, 2:34am UTC](https://www.finalbuilder.com/forums/t/xcopy-zero-files-affected-failure/93/2 "2006-05-17T02:34:01Z")

</div>

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

---

<div class="post-metadata">

### Author: ![nirsilgi](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/n/a6a055/32.png) [@nirsilgi](https://www.finalbuilder.com/forums/u/nirsilgi)
#### Post date: [May 17, 2006, 12:59pm UTC](https://www.finalbuilder.com/forums/t/xcopy-zero-files-affected-failure/93/3 "2006-05-17T12:59:19Z")

</div>

Thanks very much Tate, it helps a lot!
