This will remove all files and subfolders:
<Target Name="CleanFolder">
<PropertyGroup>
<TargetFolder>c:\clean</TargetFolder>
</PropertyGroup>
<ItemGroup>
<FilesToClean Include="$(TargetFolder)\**\*"/>
<Directories Include="$([System.IO.Directory]::GetDirectories('$(TargetFolder)', '*', System.IO.SearchOption.AllDirectories))"
Exclude="$(TargetFolder)"/>
</ItemGroup>
<Delete Files="@(FilesToClean)" ContinueOnError="true"/>
<RemoveDir Directories="@(Directories)" />
</Target>
It would also be good to drop open connections using the openfiles tool:
openfiles /disconnect /ID *