# Rename/delete file during build

**URL:** <https://www.finalbuilder.com/forums/t/rename-delete-file-during-build/5555>\
**Category:** Discussion\
**Created:** [April 17, 2017, 12:02pm UTC](https://www.finalbuilder.com/forums/t/rename-delete-file-during-build/5555 "2017-04-17T12:02:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![denholm](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/d/a87d85/32.png) [@denholm](https://www.finalbuilder.com/forums/u/denholm)\
**Post date:** [April 17, 2017, 12:02pm UTC](https://www.finalbuilder.com/forums/t/rename-delete-file-during-build/5555/1 "2017-04-17T12:02:57Z")

</div>

In source control, I have a .bat file that I would like to remove and rewrite with an empty file during build. &nbsp;I started by using the delete action, which returned success and listed the full path to the file correctly, but the file appeared to remain. &nbsp;I tried the rename action on the file as well with similar effect, the action returns success and shows the correct full path to the file to be renamed, but when I check the workspace folder, the file is still there with the original name. &nbsp;I produce the log output for the rename action below as it had more detail than the delete action:  
  
&nbsp;Rename [$Source.tfs$\scripts\xxxxx.bat] &nbsp; Show Expanded Name 4:29 PM 4:29 PM 0 milliseconds Success  
Overwrite existing file: False&nbsp;  
List each renamed file: True  
Fail if no files are renamed: True  
Renamed file ‘G:\CI\_AWS\Ws\309\Source\tfs\scripts\xxxxx.bat’ to 'G:\CI\_AWS\Ws\309\Source\tfs\scripts\xxxxx.txt’  
Rename action completed successfully  
  
When I later inspect the workspace folder, &nbsp;G:\CI\_AWS\Ws\309\Source\tfs\scripts\xxxxx.bat is still present.  
  
“G:” is a local drive on the agent, the agent is currently running as my user, and I can delete/rename this file myself so I don’t think it’s a permissions problem but even if it were, I’d assume the delete or rename action would fail. &nbsp;I would appreciate any advice on resolving this difficulty.

---

<div class="post-metadata">

**Author:** ![Sparky](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/sparky/32/10_2.png) [@Sparky](https://www.finalbuilder.com/forums/u/Sparky)\
**Post date:** [April 18, 2017, 3:09am UTC](https://www.finalbuilder.com/forums/t/rename-delete-file-during-build/5555/2 "2017-04-18T03:09:06Z")

</div>

Hi Denholm,  
  
Do you have more than one stage?   
  
Source files are copied to the workspace at the start of each stage according to the repository rules. The default repository rules will copy all repository files to the workspace at the start of every stage. I suspect that the renamed file is being re-added to the workspace in a subsequent stage. &nbsp;&nbsp;  
  
You can see which files are being copied to the workspace by the repository rules by ticking the “Log repository files copied” option in the Stage Options.&nbsp;  
  
To log the contents of the folder directly after the Rename action, add a “Run DOS Command / Batch File” action with “Command or Batch File” set to “dir $Source.tfs$\scripts$”.  
  
See [the Stage Options page](http://wiki.finalbuilder.com/display/continua/Stage+Options#StageOptions-RepositoryRules)&nbsp;in the documentation for further details on repository rules.

---

<div class="post-metadata">

**Author:** ![denholm](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/d/a87d85/32.png) [@denholm](https://www.finalbuilder.com/forums/u/denholm)\
**Post date:** [April 19, 2017, 10:43am UTC](https://www.finalbuilder.com/forums/t/rename-delete-file-during-build/5555/3 "2017-04-19T10:43:48Z")

</div>

That was it precisely. &nbsp;Thanks very much for your help.
