home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / CLIPPER / DIRFUN / RMDIRS.C < prev    next >
Text File  |  1993-11-28  |  2KB  |  105 lines

  1.  
  2.  
  3. /*
  4.  * File......   : RMDIRS.c
  5.  * Author....   : Peter Kulek
  6.  * Date......   : $Date:   02 Mar 1991  $
  7.  * Revision..   : $Revision:   1.0  $
  8.  * Log file..   : $Logfile:   c:\impala5\c\rmdirs.c  $
  9.  * Compuserve ID: 100140,1220
  10.  * 
  11.  * This is an original work by Peter Kulek
  12.  * Copyright (c) 1991  Peter Kulek 
  13.  * You can use this code as you please but please keep 
  14.  * copyright notice in code.
  15.  *
  16.  * compile with MSC 6
  17.  * Modification history:
  18.  * ---------------------
  19.  *
  20.  */
  21.  
  22.  
  23. /*  $DOC$
  24.  *  $FUNCNAME$
  25.  *     RMDIRS()
  26.  *  $CATEGORY$
  27.  *     DOS
  28.  *  $ONELINER$
  29.  *     Remove multi-level directories in a single call
  30.  *  $SYNTAX$
  31.  *     RMDIRS(cPath) -> nVal
  32.  *  $ARGUMENTS$
  33.  *     <cPath>       Drive and Path to remove
  34.  *  $RETURNS$
  35.  *     <nVal>        Dos error value
  36.  *
  37.  *  $DESCRIPTION$
  38.  *      This function removes a multi-level directory in a single call
  39.  *      If the path is not empty or an invalid path is specified 
  40.  *      nothing will be removed.
  41.  *  $EXAMPLES$
  42.  *      cFileName := '\bum\ti\ti\bum\ti\ti\bum\ti.bum'
  43.  *      if ! file(cFilename) // Check For Filename
  44.  *           MKDIRS(pathsplit(cFileName,2)) // Get path From File
  45.  *      endif
  46.  *      RMDIRS(pathsplit(cFileName,2)) // remove directory
  47.  *
  48.  *  $END$
  49.  */
  50.  
  51.  
  52. #include "extend.api"
  53.  
  54. int rmdirs( char *);
  55. int rmdir (char *) ;
  56.  
  57. #define OR ||
  58.  
  59.  
  60.  
  61. CLIPPER RMDIR() {
  62.      _retni(-1);    
  63.      if ISCHAR(1)
  64.          _retni( rmdir(_parc(1)) );
  65. }
  66.  
  67. CLIPPER RMDIRS() {
  68.      _retni(-1);    
  69.      if ISCHAR(1)
  70.          _retni( rmdirs(_parc(1)) );
  71. }
  72.  
  73. int rmdirs( char *path){
  74.       int retval = -1 ;
  75.       int i = strlen(path)+1 ;
  76.       char subpath[128] = "";
  77.       while ( i > 0 ) {
  78.           if (path[i] == '\\' OR path[i] == '/' OR path[i] == '\0') {
  79.               path[i] = '\0' ;
  80.               retval = rmdir(path) ;
  81.           }    
  82.           i-- ;
  83.       }
  84.       return(retval);
  85. }
  86.  
  87. int rmdir ( char *path){
  88.    int iRetVal;
  89.    _asm {
  90.            push dx
  91.            push ds
  92.            mov ah, 0x3a
  93.            lds dx, [path]
  94.            int 21h
  95.            mov iRetVal,0
  96.            jnc mkdir1
  97.            mov iRetVal,AX
  98.        mkdir1:
  99.            pop ds
  100.            pop dx  
  101.    } 
  102.    return(iRetVal) ;
  103. }
  104.  
  105.