Task

Walk a given directory tree and print files matching a given pattern.


Note: This task is for recursive methods.   These tasks should read an entire directory tree, not a single directory.


Note: Please be careful when running any code examples found here.



Related task

   Walk a directory/Non-recursively   (read a single directory). 


/*REXX program shows all files in a  directory tree  that match a given search criteria.*/
parse arg xdir;  if xdir=''  then xdir='\'       /*Any DIR specified?  Then use default.*/
@.=0                                             /*default result in case ADDRESS fails.*/
dirCmd= 'DIR /b /s'                              /*the DOS command to do heavy lifting. */
trace off                                        /*suppress REXX error message for fails*/
address system  dirCmd xdir  with output stem @. /*issue the DOS DIR command with option*/
if rc\==0  then do                               /*did the DOS DIR command get an error?*/
                say '***error!*** from DIR' xDIR /*error message that shows "que pasa". */
                say 'return code='  rc           /*show the  return code  from  DOS DIR.*/
                exit rc                          /*exit with    "     "     "    "   "  */
                end                              /* [↑]  bad ADDRESS cmd  (from DOS DIR)*/
#=@.rc                                           /*the number of  @.  entries generated.*/
if #==0  then #='   no   '                       /*use a better word choice for 0 (zero)*/
say center('directory '      xdir      " has "      #       ' matching entries.', 79, "─")
 
                do j=1  for #;       say @.j     /*show all the files that met criteria.*/
                end   /*j*/
exit @.0+rc                                      /*stick a fork in it,  we're all done. */