Skip to content

Commit 6bc2b79

Browse files
author
snzen
committed
*Traverse -rec
1 parent f9e15a9 commit 6bc2b79

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,3 +328,5 @@ ASALocalRun/
328328

329329
# MFractors (Xamarin productivity tool) working folder
330330
.mfractor/
331+
332+
Ignore

FilesCore/Traverse.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class Traverse : IUtil
1111
"Traverses all sub-folders of a given root and launches a process with the provided args. If specified replaces a template string" +
1212
"in the args with the current folder full path or name." + Environment.NewLine +
1313
"Args: root (-root), program to call (-proc), program args (-pargs) Put in quotes and add a single space before the pargs string. " +
14-
"current dir full path as arg name (-cdf), current dir as arg (-cd)" + Environment.NewLine +
14+
"current dir full path as arg name (-cdf), current dir as arg (-cd), recursive (-rec)" + Environment.NewLine +
1515
"Example: files -p traverse -ni -cdf $$ -cd $ -root <path> -proc <files> -pargs \" -p move -ni -zpad 3 -src $$ -dest $$ -prf $-\"";
1616

1717

@@ -23,13 +23,16 @@ public int Run(RunArgs ra)
2323
string progArgs = null;
2424
string cdf = null;
2525
string cd = null;
26+
bool recursive = false;
2627

2728
if (interactive)
2829
{
2930
string src = null;
3031
Utils.ReadString("Source dir (current): ", ref src);
3132
root = !string.IsNullOrEmpty(src) ? new DirectoryInfo(src) : ra.RootDir;
3233
Utils.ReadString("Program to run for each dir: ", ref prog, true);
34+
recursive = Utils.ReadWord("Recursive dir traversal? (y/*):", "y");
35+
3336
Utils.ReadString("Program arguments: ", ref progArgs, true);
3437
Utils.ReadString("Argument string to be replaced by the full current dir path: ", ref cdf);
3538
Utils.ReadString("Argument string to be replaced by the current dir name: ", ref cd);
@@ -41,9 +44,10 @@ public int Run(RunArgs ra)
4144
progArgs = ra.InArgs.GetFirstValue("-pargs");
4245
if (ra.InArgs.ContainsKey("-cdf")) cdf = ra.InArgs.GetFirstValue("-cdf");
4346
if (ra.InArgs.ContainsKey("-cd")) cd = ra.InArgs.GetFirstValue("-cd");
47+
if (ra.InArgs.ContainsKey("-rec")) recursive = true;
4448
}
4549

46-
foreach (var dir in root.EnumerateDirectories("*", SearchOption.AllDirectories))
50+
foreach (var dir in root.EnumerateDirectories("*", recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly))
4751
try
4852
{
4953
var pargs = progArgs;

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ files -p ext -ni -sp *.png -ext jpg
247247
program args (-pargs) Put in quotes and add a single space before the pargs string.
248248
current dir full path as arg name (-cdf)
249249
current dir as arg (-cd)
250+
recursive (-rec)
250251
Example:
251252
Renames all files by prefixing them with their folder name.
252253
files -p traverse -ni -cdf $$ -cd $ -root <path> -proc <files>

0 commit comments

Comments
 (0)