home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 375.lha / ArexxExamples / dirtree.rexx < prev    next >
OS/2 REXX Batch file  |  1990-05-02  |  2KB  |  61 lines

  1. /* This function displays all the files in the directory you select and its
  2.    subdirectories.
  3. */
  4.  
  5.  
  6. /* dirtree.rexx - lists all files in a directory, including subdirectories.
  7.                      Ron Shaw Wed Dec  6 16:33:44 1989
  8. */
  9.  
  10. arg root sil
  11.  
  12. if right(root,1) ~= ':' then
  13.   root = root || '/'
  14. if root = '/' then root = ''
  15.  
  16. /*-- Added this so we could quiet the display of dir and file names --*/
  17. if length(sil) > 0 then sil = 0
  18. else sil = 1
  19. fcount = 0                                              /* # of files */
  20. dcount = 0                                              /* # of directories */
  21.  
  22.  
  23. call dotree(root)
  24. say ' '
  25. say 'sub directories['dcount'] files['fcount']'
  26. exit
  27.  
  28. dotree: procedure expose fcount root dcount sil
  29.   parse arg x
  30.   contents = showdir(x);
  31.   do i = 1 to words(contents)
  32.     temp = x || word(contents,i)
  33.  
  34.     select
  35.       when word(statef(temp),1) = 'FILE' then do
  36.         call do_file temp
  37.         fcount = fcount + 1        /* increment the # of files we have found */
  38.         end
  39.  
  40.       /* if a directory then do next level,here is the reclusiveness ! */
  41.       when word(statef(temp),1) = 'DIR' then do
  42.             say temp '(DIR)'
  43.         dcount = dcount +1
  44.         call dotree(temp || '/')
  45.         end
  46.       otherwise signal about_it
  47.     end
  48.   end
  49. return 0
  50.  
  51. do_file:          /* this is where we do what we want with the file */
  52. arg fyl
  53.  
  54. if compare(sil,'1') == 0 then say fyl   /* display file name if asked for */
  55.  
  56. return 0
  57.  
  58. about_it:    /* error determining file type */
  59. say 'Error: File' temp 'is neither DIR nor FILE.'
  60. exit(20)
  61.