home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cenvi23.zip / PATHADD.CMD < prev    next >
OS/2 REXX Batch file  |  1995-03-31  |  1KB  |  48 lines

  1. @echo off
  2. REM **********************************************************************
  3. REM *** PathAdd.cmd - add a directory to the current path, if it's not ***
  4. REM *** ver.1         already there                                    ***
  5. REM **********************************************************************
  6. if "%1"=="" GOTO SHOW_HOW
  7. if not "%2"=="" GOTO SHOW_HOW
  8. CALL CEnviSet %0.cmd %1
  9. GOTO FINI
  10.  
  11. :SHOW_HOW
  12. ECHO PathAdd.cmd - Add a directory to the PATH if it's not already there
  13. ECHO USAGE: PathCmd DirSpec
  14. GOTO FINI
  15.  
  16.  
  17. GOTO CENVI_EXIT
  18.  
  19. main(argc,argv)
  20. {
  21.    NewDir = argv[1]
  22.    if ( AlreadyInPath(NewDir) ) {
  23.       printf("The Directory \"%s\" is already in PATH.\n",NewDir)
  24.    } else {
  25.       // File is not already in the path, and so append to the end of PATH.
  26.       // If there isn't a semi-colon at the end of PATH already, then add one.
  27.       if ( PATH[strlen(PATH)-1] != ';' )
  28.          strcat(PATH,";")
  29.       // Append this new directory to the end of the path statement
  30.       strcat(PATH,NewDir)
  31.    }
  32. }
  33.  
  34. AlreadyInPath(Dir) // search through path for this Dir, return True if found, else False
  35. {
  36.    len = strlen(Dir)
  37.    p = PATH
  38.    do {
  39.       if ( 0 == strnicmp(p,Dir,len)  && (p[len]==0 || p[len]==';') )
  40.          return(True)
  41.       p = strchr(p,';')
  42.    } while( p++ != NULL )
  43.    return(False)
  44. }
  45.  
  46. :CENVI_EXIT
  47. :FINI
  48.