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

  1. @echo off
  2. REM ********************************************************************
  3. REM *** PathDel.cmd - delete a directory from the current path if it ***
  4. REM *** ver.1         is in the current path                         ***
  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 PathDel.cmd - Delete a directory from the PATH if it's there
  13. ECHO USAGE: PathDel DirSpec
  14. GOTO FINI
  15.  
  16.  
  17. GOTO CENVI_EXIT
  18.  
  19. main(argc,argv)
  20. {
  21.    OldDir = argv[1]
  22.    if NULL == (Position = FindDirInPath(OldDir))
  23.       printf("The Directory \"%s\" is not in PATH.\n",OldDir)
  24.    else {
  25.       // copy from Path beyond this dir
  26.       strcpy(Position,Position+strlen(OldDir))
  27.       // if there is a semi-colon at this position, then copy from beyond that too
  28.       if (Position[0] == ';')
  29.          strcpy(Position,Position+1)
  30.    }
  31. }
  32.  
  33. FindDirInPath(Dir) // search through path for this Dir, return pointer if found
  34.                    // and return NULL if not found
  35. {
  36.    len = strlen(Dir)
  37.    p = PATH
  38.    do {
  39.       if ( 0 == strnicmp(p,Dir,len)  && (p[len]==0 || p[len]==';') )
  40.          return(p)
  41.       p = strchr(p,';')
  42.    } while( p++ != NULL )
  43.    return(NULL)
  44. }
  45.  
  46. :CENVI_EXIT
  47. :FINI
  48.