diff --git a/UBCopy/UBCopyHandler.cs b/UBCopy/UBCopyHandler.cs index 5559af5..55047ab 100644 --- a/UBCopy/UBCopyHandler.cs +++ b/UBCopy/UBCopyHandler.cs @@ -38,7 +38,7 @@ public class UBCopyHandler private static readonly ILog Log = LogManager.GetLogger(typeof(UBCopyHandler)); public static int ProcessFiles(string inputfile, string outputfile, bool overwrite, bool movefile, bool checksum, int buffersize, - bool reportprogress, int numberthreads, int synchronousFileCopySize, int bytesSecond) + bool reportprogress, int numberthreads, int synchronousFileCopySize, int bytesSecond, string exclusionlist) { if (string.IsNullOrEmpty(outputfile)) throw new Exception("Target cannot be empty"); @@ -52,6 +52,7 @@ public static int ProcessFiles(string inputfile, string outputfile, bool overwri UBCopySetup.Reportprogres = reportprogress; UBCopySetup.SynchronousFileCopySize = synchronousFileCopySize * 1024 * 1024; UBCopySetup.BytesSecond = bytesSecond; + UBCopySetup.Exclusionlist = exclusionlist; try { // get the file attributes for file or directory diff --git a/UBCopy/UBCopyMain.cs b/UBCopy/UBCopyMain.cs index 7b55a6d..f8f8667 100644 --- a/UBCopy/UBCopyMain.cs +++ b/UBCopy/UBCopyMain.cs @@ -41,6 +41,7 @@ class UBCopyMain //hold command line options private static string _sourcefile; private static string _destinationfile; + private static string _exclusionlist; private static bool _overwritedestination = true; //we set an inital buffer size to be on the safe side. private static int _buffersize = 16; @@ -91,7 +92,7 @@ private static int Main(string[] args) { UBCopyHandler.ProcessFiles(_sourcefile, _destinationfile, _overwritedestination, _movefile, - _checksumfiles, _buffersize, _reportprogres, _threads, _smallfilesize,_bytessecond); + _checksumfiles, _buffersize, _reportprogres, _threads, _smallfilesize, _bytessecond, _exclusionlist); } catch (Exception ex) { @@ -144,6 +145,9 @@ static public int ParseCommandLine(string[] args) { "d:|destinationfile:", "The target file you wish to write", v => _destinationfile = v}, + { "e:|exclusionlist:", "Comma-separated list of files not to copy", + v => _exclusionlist = v}, + { "o:|overwritedestination:", "True if you want to overwrite the destination file if it exists", (bool v) => _overwritedestination = v}, diff --git a/UBCopy/UBCopySetup.cs b/UBCopy/UBCopySetup.cs index bb3d9c9..9d438da 100644 --- a/UBCopy/UBCopySetup.cs +++ b/UBCopy/UBCopySetup.cs @@ -28,6 +28,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using log4net; namespace UBCopy @@ -54,7 +55,7 @@ public static class UBCopySetup public static int BytesSecond; public static bool ForceCopy; public static bool SyncFolders; - + public static string Exclusionlist; public static bool Listlocked; public static readonly object DictonaryLocker = new object(); @@ -67,6 +68,8 @@ public static void TraverseTree(string root) string[] destinationFolderList = Destinationfile.Contains(",") || Destinationfile.Contains(";") ? Destinationfile.Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries) : new string[] { Destinationfile }; + string[] exclusionlist = Exclusionlist != null ? Exclusionlist.Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries).Select(f => f.Trim()).ToArray() : null; + var dirs = new Stack(20); if (!Directory.Exists(root)) @@ -116,6 +119,11 @@ public static void TraverseTree(string root) foreach (var file in files) { + if (exclusionlist!= null && exclusionlist.Contains(Path.GetFileName(file), StringComparer.OrdinalIgnoreCase)) + { + continue; + } + if (file.Length < 261) { try