home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cenvi23.zip / ALLDIRS.CMD next >
OS/2 REXX Batch file  |  1994-10-03  |  2KB  |  64 lines

  1. /*************************************************************************
  2.  *** AllDirs.cmd - Perform the given command in the current directory  ***
  3.  *** ver.1         and in all subdirectories of the current directory. ***
  4.  ***               perform in directories top-down.                    ***
  5.  *************************************************************************/
  6. '@echo OFF'
  7. SETLOCAL
  8. VALUE(ALLDIRS_CMD,ARG(1),'OS2ENVIRONMENT')
  9. 'CEnvi2.exe %0.cmd'
  10. SIGNAL CENVI_EXIT
  11.  
  12. main(argc,argv)
  13. {
  14.    if ( !defined(ALLDIRS_CMD)  ||  !strcmp(ALLDIRS_CMD,"/?") )
  15.       Instructions();
  16.    else {
  17.       // build a tree of all directories from the current point downward
  18.       list = Directory(FullPath("*"),TRUE,FATTR_RDONLY|FATTR_HIDDEN|FATTR_SYSTEM|FATTR_SUBDIR|FATTR_ARCHIVE,FATTR_SUBDIR)
  19.       // first perform command in current directory
  20.       RememberDir = FullPath(".")
  21.       PerformCommand()
  22.       if ( NULL != list ) {
  23.          listCount = 1 + GetArraySpan(list)
  24.          for ( i = 0; i < listCount; i++ ) {
  25.             // change to each subdirectory and perform command there
  26.             ChangeToDirectory(list[i].name)
  27.             PerformCommand()
  28.          }
  29.          ChangeToDirectory(RememberDir)
  30.       }
  31.    }
  32. }
  33.  
  34. PerformCommand()
  35. {
  36.    printf("%s",ALLDIRS_CMD)
  37.    system(ALLDIRS_CMD);
  38. }
  39.  
  40. ChangeToDirectory(DirName)
  41. {
  42.    printf("\n%s: ",DirName)
  43.    #define ORD_DOS32SETCURRENTDIR   255
  44.    DynamicLink("doscalls",ORD_DOS32SETCURRENTDIR,BIT32,CDECL,DirName)
  45. }
  46.  
  47. Instructions()
  48. {
  49.    printf("\n")
  50.    printf("AllDirs - Perform a command in this directory and all subdirectories\n")
  51.    printf("\n")
  52.    printf("SYNTAX: AllDirs commands...\n")
  53.    printf("\n")
  54.    printf("Where: commands is any commands to perform in each directory\n")
  55.    printf("\n")
  56.    printf("Examples: This example deletes all *.bak files in this directory and in\n")
  57.    printf("          directories below this one:\n")
  58.    printf("            AllDirs del *.bak\n")
  59.    printf("\n")
  60. }
  61.  
  62. CENVI_EXIT:
  63. ENDLOCAL
  64.