Is there a convenient way to check if a directory is empty using MSBuild?
Create an item and see if it contains anything, like this:
<Target Name="CheckDirectoryForEmpty">
<PropertyGroup>
<EmptyCheck>./PathTo/DirectoryToCheck/*.*</EmptyCheck>
</PropertyGroup>
<ItemGroup>
<EmptyCheck Include="$(EmptyCheck)" />
</ItemGroup>
<Message
Condition="'@(EmptyCheck)' == ''"
Text="Directory '$(EmptyCheck)' is empty"
/>
</Target>
To check recursively, use **/*.*
instead of *.*
in the path.
You could use one of the tasks in the MSBuild Extension Pack for this. Use the FindUnder
task, and check whether FoundItems
is empty.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With