Rename files and Folders with Regex

Jun 19, 2009 at 9:50 PM

I am creating a folder structure from a prototype structure and want to rename where the file/folder name matches a simple replacement text string. For example:




with a regex PrototypeName  replaced with NewName. Is there a task or tasks to help me do this? I have searched the documentation, but it seems like there isn't. Have I missed something?

Jun 23, 2009 at 12:07 PM


I don't believe there is a task to address that right now. Mike

Jun 23, 2009 at 5:49 PM

Thanks Mike. I have used a combination of a Community Task and an ExtensionPack task:

	<Target Name="MoveFiles">
			<AllFiles Include="$(SolutionPath)\**\*.*" />
		<MSBuild.Community.Tasks.RegexMatch Expression="$(PrototypeName)" Input="%(AllFiles.FullPath)">
			<Output TaskParameter="Output" ItemName="MatchedFiles" />
		<MSBuild.ExtensionPack.Framework.TextString TaskAction="Replace" NewValue="$(SolutionName)" OldString="%(MatchedFiles.FullPath)" OldValue="$(PrototypeName)">
			<Output TaskParameter="NewString" ItemName="NewFiles" />
		<Copy SourceFiles="@(MatchedFiles)" DestinationFiles="@(NewFiles)" />
		<Delete Files="@(MatchedFiles)" />

(I am cloning a visual studio solution called PrototypeName)

Let me know if you spot a better way:-)

Jun 23, 2009 at 7:35 PM

If its working for you, great! You may be able to use the FindUnder task instead of the community task. It depends on your regex. will ship with a Get TaskAction for folder which supports full regex.