-
Notifications
You must be signed in to change notification settings - Fork 22
FileSet
Yevhen Bobrov edited this page Jun 22, 2014
·
9 revisions
// use object initializer to specify file selection paths
var files = new FileSet
{
"a.txt",
"b.txt"
}
// use globbing patterns, like '**' for recursive selection
// and standard wildcards, like '*' and '?' are supported as well
var files = new FileSet
{
@"Output\**\*.txt",
"b?.txt"
}
// file set supports TeamCity-style inclusion/exclusion patterns
// the below spec will exclude all files with the name 'b.txt'
var files = new FileSet
{
@"Output\**\*.txt",
"-:b.txt"
}
// separate multiple patterns with '|' symbol
var files = new FileSet
{
@"Output\**\*.txt|-:b.txt"
}
// use implicit conversions, to convert
// from string to file set and vice versa
FileSet testAssemblies = @"{outputPath}\*.Tests.dll";
// the implicit conversion from file set to string
// will resolve all paths and will return string
// with all file paths separated by ' '
Cmd(@"nunit-console.exe {testAssemblies}");
// use implicit conversion from/to string array
string[] files = new FileSet{"*.txt"};
FileSet files = new string[]{"a.txt", "*.rc"};
// you can enumerate file set, which will
// give you back fully resolved file paths
foreach (var path in new FileSet{"*.txt"})
Console.WriteLine(path);
// the implicit conversion from file set to string
// will resolve all paths and will return string
// with all file paths separated by ' '
Cmd(@"nunit-console.exe {tests}");
// use explicit add methods to manipulate file set
var files = new FileSet();
files.Add("a.txt|b.txt");
files.Add(new[]{"a.txt", "b.txt|c.txt"});
// use explicit inclusion/exclusion methods
var files = new FileSet();
files.Include("*.txt");
files.Exclude("b.txt");
// exclude files by Regex
FileSet files = @"**\*.*";
files.Exclude(new Regex("[0-9]+\.txt"));
// exclude files by custom function
// (refer to FileSet.Item below for details)
FileSet files = @"**\*.*";
files.Exclude(item => item.Extension == "txt");
// you can use Resolve() method to get back
// fully resolved file paths as FileSet.Item structures
// (refer to FileSet.Item below for details)
foreach (var item in new FileSet{@"**\*.txt"}.Resolve())
Console.WriteLine(item.RecursivePath);You can also specify base path ala NAnt, when constructing FileSet.
// so instead of this
var files = new FileSet
{
@"Output\Nake.dll",
@"Output\Utility.dll"
}
// you can do this
var files = new FileSet("Output")
{
"Nake.dll",
"Utility.dll"
}Having the following hierarchy:
A
|__ F1.txt
|__ F2.txt
|__ B
|__ F3.txt
|__ F4.txt
After running this code:
FileSet tree = @"**\*;**\*.*";
var mirrored = tree.Mirror("Dir");mirrored will have the following paths:
Dir
|__ A
|__ F1.txt
|__ F2.txt
|__ B
|__ F3.txt
|__ F4.txt