Msbuild find all directories containing a file named xxxx

Given the folder structure:

parentFolder
  - 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 these folder paths I need to complete the copy task.

+3
source share
1 answer

Here is one of them:

<?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 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\
  =====================
+13
source

Source: https://habr.com/ru/post/1735432/


All Articles