It is however pretty easy to do by combining the Delete and RemoveDir tasks together. Below is a code snippet that does it.
The code should be self-explanatory enough with the few comments.
<Project ToolsVersion="3.5" DefaultTargets="Default" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> <!-- Folder to clean - Trailing slash required --> <DeleteRoot>D:\Test\Deploy\</DeleteRoot> </PropertyGroup> <Target Name="Default"> <ItemGroup> <!-- Item to get all files recursively in the DeleteRoot folder --> <FilesToDelete Include="$(DeleteRoot)\**\*.*" /> <!-- Item to get all folders from the files to be deleted --> <FoldersToDelete Include="%(FilesToDelete.RootDir)%(FilesToDelete.Directory)" Exclude="$(DeleteRoot)"/> </ItemGroup> <!-- Display what will be deleted --> <Message Text=" # @(FilesToDelete)" Importance="normal" /> <Message Text=" # @(FoldersToDelete)" Importance="normal" /> <!-- Delete the files --> <Delete Files="@(FilesToDelete)" Condition=" $(DeleteRoot)!=''" /> <!-- Remove the folders --> <RemoveDir Directories="@(FoldersToDelete)" Condition="$(DeleteRoot)!=''" /> </Target> </Project>
2 comments:
Very good! Helped me alot, thank you!
Glad it helped you! Thank you for letting me know :-)
Post a Comment