Skip to content

Commit

Permalink
Ability to exclude files from source folder
Browse files Browse the repository at this point in the history
  • Loading branch information
IlyaFinkelshteyn committed Jan 17, 2019
1 parent e36b2d9 commit 3d4b0de
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
3 changes: 2 additions & 1 deletion UBCopy/UBCopyHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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
Expand Down
6 changes: 5 additions & 1 deletion UBCopy/UBCopyMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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},

Expand Down
10 changes: 9 additions & 1 deletion UBCopy/UBCopySetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using log4net;

namespace UBCopy
Expand All @@ -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();
Expand All @@ -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<string>(20);

if (!Directory.Exists(root))
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3d4b0de

Please sign in to comment.