home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Interactive Guide / c-cplusplus-interactive-guide.iso / c_ref / csource1 / cenvid / alldirs.bat next >
DOS Batch File  |  1993-09-21  |  2KB  |  73 lines

  1. @echo off
  2. REM *************************************************************************
  3. REM *** AllDirs.bat - Perform the given command in the current directory  ***
  4. REM ***               and in all subdirectories of the current directory. ***
  5. REM ***               perform in directories top-down.                    ***
  6. REM *************************************************************************
  7.  
  8. REM *****************************************************************
  9. REM *** Build ALLDIRS_CMD environment variable to all input parms ***
  10. REM *****************************************************************
  11.    SET ALLDIRS_CMD=
  12.    :NEXT_ARG
  13.       IF q%1q == qq GOTO NO_MORE_ARGS
  14.       SET ALLDIRS_CMD=%ALLDIRS_CMD% %1
  15.       SHIFT
  16.       GOTO NEXT_ARG
  17.    :NO_MORE_ARGS
  18.  
  19. CEnvi.exe AllDirs.bat
  20. GOTO CENVI_EXIT
  21.  
  22. main()
  23. {
  24.    if ( !defined(ALLDIRS_CMD)  ||  !strcmp(ALLDIRS_CMD,"/?") )
  25.       Instructions();
  26.    else {
  27.       // build a tree of all directories from the current point downward
  28.       list = Directory(FullPath("*.*"),TRUE,FATTR_RDONLY|FATTR_HIDDEN|FATTR_SYSTEM|FATTR_SUBDIR|FATTR_ARCHIVE,FATTR_SUBDIR)
  29.       // first perform command in current directory
  30.       RememberDir = FullPath(".")
  31.       PerformCommand()
  32.       if ( NULL != list ) {
  33.          listCount = 1 + GetArraySpan(list)
  34.          for ( i = 0; i < listCount; i++ ) {
  35.             // change to each subdirectory and perform command there
  36.             ChangeToDirectory(list[i].name)
  37.             PerformCommand()
  38.          }
  39.          ChangeToDirectory(RememberDir)
  40.       }
  41.    }
  42. }
  43.  
  44. PerformCommand()
  45. {
  46.    printf("%s",ALLDIRS_CMD)
  47.    system(P_SWAP,ALLDIRS_CMD);
  48. }
  49.  
  50. ChangeToDirectory(DirName)
  51. {
  52.    printf("\n%s: ",DirName)
  53.    system("cd %s",DirName);
  54. }
  55.  
  56. Instructions()
  57. {
  58.    printf("\n")
  59.    printf("AllDirs - Perform a command in this directory and all subdirectories\n")
  60.    printf("\n")
  61.    printf("SYNTAX: AllDirs commands...\n")
  62.    printf("\n")
  63.    printf("Where: commands is any commands to perform in each directory\n")
  64.    printf("\n")
  65.    printf("Examples: This example deletes all *.bak files in this directory and in\n")
  66.    printf("          directories below this one:\n")
  67.    printf("            AllDirs del *.bak\n")
  68.    printf("\n")
  69. }
  70.  
  71. :CENVI_EXIT
  72. SET ALLDIRS_CMD=
  73.