I have a set of files inside a folder. They all have a name which matches the pattern DR__.*. I want to copy them to another folder, but removing the DR__ prefix. How can I do t
I agree with @Si's solution. But with MSBuild 4.0 you can do it with built in functionality. NAnt script is much clearer than mine. But I will add it as a solution just to show MSBuild 4.0 techniques:
%(CVParameters.FileName)%(CVParameters.Extension)
DR__
$(Prefix.Length)
$(OriginalFileName.Length)
$([MSBuild]::Subtract($(OriginalFileNameLength),$(PrefixLength)))
$(OriginalFileName.Substring($(PrefixLength),$(SubstringLength)))
$([System.IO.Path]::Combine($(DestinationDir),$(ModifiedFileName)))
Edit (by OP): To get this working, I had to replace $(DestinationFullPath)
in Copy
with @(DestinationFullPath)
, to match the number of Source and Destination Files. Also, I had to change the prefix to DR__
, since DR__.
wouldn't work.