home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / cprog / actlib12.zip / TOOLS.ZIP / SETCWD.C < prev    next >
C/C++ Source or Header  |  1993-02-25  |  1KB  |  45 lines

  1. /*  Copyright (C) 1993   Marc Stern  (internet: stern@mble.philips.be)  */
  2.  
  3. #include "tools.h"
  4. #include <stdlib.h>
  5. #include <direct.h>
  6. #include <ctype.h>
  7.  
  8.  
  9. /***
  10.  *
  11.  *  Function   :    setcwd
  12.  *
  13.  *  Topics     :    change to specified directory accross disks
  14.  *
  15.  *  Parameters :    in    char *dir    input directory name
  16.  *
  17.  *  Return code:    0      OK
  18.  *                  other  Invalid syntax, drive or path
  19.  ***/
  20.  
  21.  
  22.  
  23.  
  24. int setcwd( const char *dir )
  25.  
  26. { char drive[_MAX_DRIVE], buffer[_MAX_PATH];
  27.   int currentdisk = _getdrive();
  28.  
  29.   _splitpath( dir, drive, buffer, buffer, buffer );
  30.  
  31.   if ( *drive ) { int disk = toupper(*drive) - 'A' + 1;
  32.                   _chdrive( disk );
  33.                   if ( disk != _getdrive() )
  34.                      { _chdrive( currentdisk );
  35.                        return -1;
  36.                      }
  37.                 }
  38.  
  39.   if ( chdir(dir) ) { _chdrive( currentdisk );
  40.                       return -1;
  41.                     }
  42.  
  43.   return 0;
  44. }
  45.