1
/* FileTransformation.cs
3
* GNOME Do is the legal property of its developers. Please refer to the
4
* COPYRIGHT file distributed with this source distribution.
6
* This program is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation, either version 3 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program. If not, see <http://www.gnu.org/licenses/>.
26
namespace Do.FilesAndFolders
29
public delegate bool IncludeFile (string source);
30
public delegate void TransformFile (string source, string destination);
33
/// A class representing a recursive file transformation.
35
public class FileTransformation
38
static bool DefaultIncludeFile (string source)
40
return !". ..".Contains (Path.GetFileName (source));
43
public TransformFile Transformation { get; private set; }
44
public IncludeFile Include { get; private set; }
46
public FileTransformation (TransformFile transform) :
47
this (transform, DefaultIncludeFile)
51
public FileTransformation (TransformFile transform, IncludeFile include)
53
Transformation = transform;
58
/// Recursively perform transformation an all files at or below source
61
/// <param name="source">
62
/// A <see cref="System.String"/> source file or directory to transform.
64
/// <param name="destination">
65
/// A <see cref="System.String"/> destination file or directory to transform to.
67
public void Transform (string source, string destination)
69
string target = Path.Combine (destination, Path.GetFileName (source));
70
Transformation (source, target);
71
if (Directory.Exists (source)) {
72
Directory.GetFileSystemEntries (source)
73
.Where (f => Include (f))
74
.ForEach (f => Transform (f, target));