tags:

views:

79

answers:

2

Hi,

I'm trying to write an MsBuild script to zip some files up. I need to select all of the read-only files recursively from a folder into an ItemGroup to add to the zip.

I'm using the community tasks Zip task, but am struggling with selecting files based on their attributes.

Is there anything around to do this out of the box, or do I need to write a custom task?

Thanks for you help.

+1  A: 

Have you looked at the community build tasks site?

It has a zip task and an attribute change task - they should get you most of they way there.

Oded
Hi, yes, I should have said - I'm using their Zip task. As you say, the Attrib task will change attributes, but I don't want to change them, I just want to select files based on their attributes.
Scott Langham
A: 

This seems to do the job with a bit of dirty command line usage.

<Exec Command="dir .\RelPath\ToFolder\ToSearchIn /S /AR /B > readonlyfiles.temp.txt"/>
<ReadLinesFromFile File="readonlyfiles.temp.txt">
    <Output TaskParameter="Lines" ItemName="ReadOnlyFiles"/>
</ReadLinesFromFile>
<Delete Files="readonlyfiles.temp.txt"/>

That gives absolute paths to the files.

To get relative paths, try something like this:

<Exec Command="dir .\RelPath\ToFolder\ToSearchIn /S /AR /B > readonlyfiles.temp.txt"/>
<FileUpdate Files="readonlyfiles.temp.txt"
            Multiline="True"
            Regex="^.*\\RelPath\\ToFolder\\ToSearchIn"
            ReplacementText="RelPath\ToFolder\ToSearchIn"
            />
<ReadLinesFromFile File="readonlyfiles.temp.txt">
    <Output TaskParameter="Lines" ItemName="ReadOnlyZipFiles"/>
</ReadLinesFromFile>
<Delete Files="readonlyfiles.temp.txt"/>
Scott Langham