Given a folder structure:
pa开发者_运维问答rentFolder
- ChildFolder1
- somefiletolookfor.txt
- (other files and folder)
- ChildFolder2
- (other files and folder)
- ChildFolder3
- (other files and folder)
- ChildFolder4
- somefiletolookfor.txt
- (other files and folder)
- ChildFolder5
- (other files and folder)
I would like to get the folder paths for ChildFolder1 and ChildFolder4. And for each of those folder paths I need to do a copy task.
Here is one that would work:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Demo" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<AllFiles Include="ChildFolder*\**"/>
<SpecificFiles Include="ChildFolder*\somefiletolookfor.txt" />
</ItemGroup>
<Target Name="Demo">
<Message Text="AllFiles: @(AllFiles)"/>
<Message Text="====================="/>
<Message Text="SpecificFiles: @(SpecificFiles)"/>
<Message Text="====================="/>
<Message Text="Specific Dirs: @(SpecificFiles->'%(RootDir)%(Directory)')"/>
<Message Text="====================="/>
</Target>
</Project>
Here is the result for the sample files that I made:
AllFiles: ChildFolder1\other.txt;ChildFolder1\somefiletolookfor.txt;ChildFolder2\other.txt;ChildFolder3\other.txt;ChildFolder4\other.txt;C
hildFolder4\somefiletolookfor.txt;ChildFolder5\other.txt
=====================
SpecificFiles: ChildFolder1\somefiletolookfor.txt;ChildFolder4\somefiletolookfor.txt
=====================
Specific Dirs: C:\Data\Ibrahim\Development\MSBuild\FindFolders\ChildFolder1\;C:\Data\Ibrahim\Development\MSBuild\FindFolders\ChildFolder4\
=====================
精彩评论