0

I'm writing a simple MS build script to delete all files inside a folder that are not being used by my program. All the files that are being used are stored inside my .txt file, that looks like this:

...
/media/50067/d.png
/media/12311/takeover.png
/media/18536/iprima.png
/media/26467/iab_filmstrip_as3.zip
...

Is it possible to read my text file line by line fill the Exclude property, so that all my files, that are listed in the text file would be excluded from deletion ?

This stack owerflow theard has suggested using ReadLinesFrom file, but after reading msdn I was not able to grasp it...

my MS build looks like this:

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <Target Name="DeleteNotUsedFiles">
        <ItemGroup>
            <Files
                Include="Desktop\media\**\*.*"
                Exclude="???"
            />
        </ItemGroup>  
        <Delete Files="@(Files)" />
    </Target>
</Project>
Community
  • 1
  • 1
Stralos
  • 4,895
  • 4
  • 22
  • 40

1 Answers1

1

All you need to do is use ReadLinesFromFile to populate an item with the content of the file, i.e. the paths of the files to exclude. Then use that ItemGroup for the Exclude attribute:

<Target Name="DeleteUnusedFiles">
  <ReadLinesFromFile File="exclude.txt">
    <!-- This makes an Item 'FilesToExclude' with all lines -->
    <Output TaskParameter="Lines" ItemName="FilesToExclude"/>
  </ReadLinesFromFile>
  <ItemGroup>
    <Files Include="Desktop\media\**\*.*"
           Exclude="@(FilesToExclude)"/> <!-- Use said Item -->
  </ItemGroup>
  <Message Text="Deleting @(Files)" />
</Target>
stijn
  • 34,664
  • 13
  • 111
  • 163