Skip to content

Commit 4796fc3

Browse files
committed
Duplicates -ni
1 parent 32dd078 commit 4796fc3

File tree

1 file changed

+32
-12
lines changed

1 file changed

+32
-12
lines changed

FilesCore/Duplicates.cs

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,35 +15,55 @@ public class Duplicates : IUtil
1515
public string Name => "duplicates";
1616
public string Info =>
1717
"Detects file duplicates in one or more folders by comparing sizes, names or data hashes." + Environment.NewLine +
18-
"There are extension and size filters as well as an option for partial hashing by skip/taking portions of the files.";
18+
"There are extension and size filters as well as an option for partial hashing by skip/taking portions of the files." + Environment.NewLine +
19+
"Args: not interactive (-ni), dirs to search into separated by semicolons (-dirs), search pattern (-sp), recursive (-rec), compare with hash (-hash), parallel (-j) ";
1920

2021
public int Run(RunArgs ra)
2122
{
23+
bool interactive = !ra.InArgs.ContainsKey("-ni");
24+
2225
var srcDirs = new List<DirectoryInfo>();
2326
var srcs = string.Empty;
2427
var skipLessThanSize = 1;
2528
var skipMoreThanSize = -1;
2629
var ignExt = string.Empty;
2730
var iExt = new List<string>();
31+
var compHash = false;
32+
var recursive = false;
33+
var inParallel = 1;
2834

29-
Utils.ReadString("Enter folders to search into, separated by semicolon: ", ref srcs, true);
30-
Utils.ReadString("Search pattern (*.*): ", ref ra.State.SearchPattern);
31-
var recursive = !Utils.ReadWord("Recursive search (default is yes)? (n/*): ", "n");
32-
Utils.ReadInt($"Skip if size < 1Kb: ", ref skipLessThanSize, false);
33-
Utils.ReadInt($"Skip if size > #Kb: ", ref skipMoreThanSize, false);
34-
Utils.ReadString("Skip extensions (.xyz): ", ref ignExt, false);
35+
ra.State.SearchPattern = "*.*";
36+
37+
if (interactive)
38+
{
39+
40+
Utils.ReadString("Enter folders to search into, separated by semicolon: ", ref srcs, true);
41+
Utils.ReadString("Search pattern (*.*): ", ref ra.State.SearchPattern);
42+
recursive = !Utils.ReadWord("Recursive search? (n/*): ", "n");
43+
Utils.ReadInt($"Skip if size < 1Kb: ", ref skipLessThanSize, false);
44+
Utils.ReadInt($"Skip if size > #Kb: ", ref skipMoreThanSize, false);
45+
Utils.ReadString("Skip extensions (.xyz): ", ref ignExt, false);
46+
compHash = Utils.ReadWord("Compare file names (default) or MD5 hashes? (h/*): ", "h");
47+
}
48+
else
49+
{
50+
if (ra.InArgs.ContainsKey("-dirs")) srcs = ra.InArgs.GetFirstValue("-dirs");
51+
else throw new ArgumentNullException("-dirs");
52+
if (ra.InArgs.ContainsKey("-sp")) ra.State.SearchPattern = ra.InArgs.GetFirstValue("-sp");
53+
if (ra.InArgs.ContainsKey("-rec")) recursive = true;
54+
if (ra.InArgs.ContainsKey("-j")) inParallel = int.Parse(ra.InArgs.GetFirstValue("-j"));
55+
if (ra.InArgs.ContainsKey("-hash")) compHash = true;
56+
}
3557

3658
if (!string.IsNullOrEmpty(ignExt))
3759
foreach (var ext in ignExt.Split(';'))
3860
iExt.Add(ext.Trim());
3961

40-
var compHash = Utils.ReadWord("Compare file names (default) or MD5 hashes? (h/*): ", "h");
41-
var inParallel = 1;
4262
var useStreamReduction = false;
4363
var take = 4000;
4464
var skip = 10000;
4565

46-
if (compHash)
66+
if (compHash && interactive)
4767
{
4868
Utils.ReadInt($"Concurrent readers (1-{Environment.ProcessorCount}): ", ref inParallel);
4969
"By default the hash is computed over the whole file.".PrintLine();
@@ -220,13 +240,13 @@ public int Run(RunArgs ra)
220240

221241
if (totalDuplicates > 0)
222242
{
223-
ra.Trace = Utils.ReadWord("Trace? (y/*): ", "y");
243+
ra.Trace = !interactive || Utils.ReadWord("Trace? (y/*): ", "y");
224244

225245
if (ra.Trace) sb.ToString().PrintLine(ConsoleColor.Yellow);
226246

227247
var opt = string.Empty;
228248

229-
if (Utils.PickOption("Save results? (xml, json, txt/*): ", ref opt, false, "xml", "json", "txt"))
249+
if (interactive && Utils.PickOption("Save results? (xml, json, txt/*): ", ref opt, false, "xml", "json", "txt"))
230250
{
231251
var fn = string.Empty;
232252
var data = string.Empty;

0 commit comments

Comments
 (0)