コード例 #1
0
ファイル: TestImgOrg.cs プロジェクト: Burkhardt/ImgOrg.Test
 public void TestMoveToTree()
 {
     #region setup variables
     var testFileDir = new RaiFile("~/Foscam/test/raw_orig").FullName;
     var sourceDir   = new RaiFile("~/Foscam/test/raw").FullName;
     var destDirRoot = testFileDir;
     foreach (var file in Directory.EnumerateFiles(testFileDir, "*.jpg"))
     {
         new RaiFile(file).CopyTo(new string[] { sourceDir });
     }
     #endregion
     #region check preconditions
     Assert.True(Directory.EnumerateFiles(sourceDir).Count() > 0);
     int initialDirCount = Directory.EnumerateDirectories(testFileDir).Count();
     int rawFileCount    = Directory.EnumerateFiles(sourceDir).Count();
     #endregion
     int count = ImageTreeFile.MoveToTree(
         fromDir: sourceDir, toDirRoot: destDirRoot,
         filter: "*.jpg", remove: "000DC5D78BAA(DLEXP)_0_");
     #region check postconditions
     Assert.True(Directory.EnumerateFiles(sourceDir).Count() == 0);
     Assert.True(Directory.EnumerateDirectories(sourceDir).Count() == 0);
     Assert.True(Directory.EnumerateDirectories(testFileDir).Count() >= initialDirCount);
     #endregion
     #region clean up
     #endregion
 }
コード例 #2
0
ファイル: Program.cs プロジェクト: Burkhardt/iorg
 static void Main(string[] args)
 {
     #region check for proper calling
     if (args.Length < 1 || args.Length > 4)
     {
         Console.WriteLine($"usage: [filter=<filter>] [remove=<removeString>] [from=<sourceDirectory>] [to=<destDirectory>]");
         Console.WriteLine("examples:");
         Console.WriteLine("\tiorg filter=*.png from=. to=.");
         Console.WriteLine("\tiorg filter=*.jpeg from=. to=..");
         return;
     }
     #endregion
     #region get all options, named and unnamed params
     var options    = from _ in args where _[0] == '-' select _;
     var namedVars  = from _ in args where _.Contains("=") select _;
     var unnamedVar = from _ in args where !(_[0] == '-' || _.Contains("=")) select _;
     #endregion
     var p = new Dictionary <string, string>();
     #region set named parameters to dictionary
     foreach (var elem in namedVars)
     {
         var list = elem.Split('=');
         p.Add(list[0], list[1]);
     }
     #endregion
     #region set all params for the rename call
     if (!p.ContainsKey("to") || string.IsNullOrEmpty(p["to"]) || p["to"] == ".")
     {
         p["to"] = Directory.GetCurrentDirectory();
     }
     if (!p.ContainsKey("from") || string.IsNullOrEmpty(p["from"]) || p["from"] == ".")
     {
         p["from"] = Directory.GetCurrentDirectory();
     }
     if (!p.ContainsKey("filter") || string.IsNullOrEmpty(p["filter"]))
     {
         p["filter"] = "*.jpg";
     }
     if (!p.ContainsKey("remove") || string.IsNullOrEmpty(p["remove"]))
     {
         p["remove"] = "";
     }
     #endregion
     var count = ImageTreeFile.MoveToTree(
         fromDir: p["from"],
         toDirRoot: p["to"],
         filter: p["filter"],
         remove: p["remove"]);
     Console.WriteLine($"{count} files moved.");
 }