Rename/delete file during build

In source control, I have a .bat file that I would like to remove and rewrite with an empty file during build.  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.  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.  I produce the log output for the rename action below as it had more detail than the delete action:

 Rename [$Source.tfs$\scripts\xxxxx.bat]   Show Expanded Name 4:29 PM 4:29 PM 0 milliseconds Success
Overwrite existing file: False 
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,  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.  I would appreciate any advice on resolving this difficulty.

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.   

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. 

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 in the documentation for further details on repository rules.



That was it precisely.  Thanks very much for your help.