Skip to content
Yevhen Bobrov edited this page Apr 3, 2020 · 6 revisions

File-system convenience functions.

NOTE: Internally, uses corresponding MSBuild tasks (by simply wrapping them), so all bugs and constraints of the following functions are the same as for the original MSBuild tasks.

Copying files

using static Nake.FS;

// copy "a.txt", "b.txt" to "aa.txt", "bb.txt"
Copy(
    new[]{"a.txt", "b.txt"},
    new[]{"bb.txt", "bb.txt"},
    overwriteReadOnlyFiles: false,         // optional
    skipUnchangedFiles: true               // optional
);

// copy "a.txt", "b.txt" to folder "Dir"
Copy(
    new[]{"a.txt", "b.txt"},
    "Dir",
    overwriteReadOnlyFiles: false,         // optional
    skipUnchangedFiles: true               // optional
);

// recursively copy all files ending with ".txt" to folder "Dir",
// excluding file with the name "foo.txt" (globbing patterns)
Copy(
    @"**\*.txt|-:foo.txt",                 
    "Dir",
    overwriteReadOnlyFiles: false,         // optional
    skipUnchangedFiles: true               // optional
);

There is also an overload which takes FileSet as first parameter.

NOTE: You can copy only files with this function. Directories cannot be included as in the original MSBuild's Copy task.

Moving files

using Nake.FS;

// move "a.txt", "b.txt" to "aa.txt", "bb.txt"
Move(
    new[]{"a.txt", "b.txt"},
    new[]{"bb.txt", "bb.txt"},
    overwriteReadOnlyFiles: false          // optional
);

// move "a.txt", "b.txt" to folder "Dir"
Move(
    new[]{"a.txt", "b.txt"},
    "Dir",
    overwriteReadOnlyFiles: false          // optional
);

// recursively move all files ending with ".txt" to folder "Dir", 
// excluding file with the name "foo.txt" (globbing patterns)
Move(
    @"**\*.txt|-:foo.txt",               
    "Dir",
    overwriteReadOnlyFiles: false          // optional
);

There is also an overload which takes FileSet as first parameter.

Deleting files

using Nake.FS;

// delete files "a.txt" and "b.txt"
Delete("a.txt", "b.txt");

// recursively delete all files ending with ".txt",
// excluding file with the name "foo.txt" (globbing patterns)
Delete(@"**\*.txt|-:foo.txt");             

Creating directories

using Nake.FS;

// create directories "Foo" and "Bar
MakeDir("Foo", "Bar");

Deleting directories

using Nake.FS;

// delete directories "Foo" and "Bar
RemoveDir("Foo", "Bar");

// recursively delete directories starting from "Foo" (globbing patterns)
RemoveDir("Foo\**\*");

Checking file freshness

using Nake.FS;

// checks that "codegened.cs" file exists and is up to date
// in respect to set of files ending with ".dbml" extension  (globbing patterns)
if (!UpToDate("codegened.cs", "*.dbml")
    ...
Clone this wiki locally