@@ -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 ;
0 commit comments