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

  1.  
  2.  
  3. /*
  4.  * File......   : MKDIRS.c
  5.  * Author....   : Peter Kulek
  6.  * Date......   : $Date:   06 Jan 1991  $
  7.  * Revision..   : $Revision:   1.0  $
  8.  * Log file..   : $Logfile:   c:\impala5\c\mkdirs.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.  *     MKDIRS()
  26.  *  $CATEGORY$
  27.  *     DOS
  28.  *  $ONELINER$
  29.  *     Build multi-level directories in a single call
  30.  *  $SYNTAX$
  31.  *     MKDIRS(cPath) -> nVal
  32.  *  $ARGUMENTS$
  33.  *     <cPath>       Drive and Path to build
  34.  *  $RETURNS$
  35.  *     <nVal>        Dos error value
  36.  *
  37.  *  $DESCRIPTION$
  38.  *      This function builds a multi-level directory in a single call
  39.  *      If the path already exists or an invalid path is specified 
  40.  *      nothing will be built.
  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.  *      copy something to cFileName or whatever
  47.  *
  48.  *  $END$
  49.  */
  50.  
  51. int mkdir ( char *);
  52. int mkdirs( char *);
  53. extern int strlen( char *); // avaiable in clipper 
  54.  
  55. #define OR ||
  56.  
  57. #include "extend.h"
  58.  
  59. // Clipper versions
  60. CLIPPER MKDIRS() {  // Build multi-level directories
  61.      _retni(-1);    
  62.      if ISCHAR(1)
  63.          _retni( mkdirs(_parc(1)) );
  64. }
  65. CLIPPER MKDIR() {  // Build single directory
  66.      _retni(-1);    
  67.      if ISCHAR(1)
  68.          _retni( mkdir(_parc(1)) );
  69. }
  70.  
  71. // c Versions 
  72. int mkdirs( char *path){
  73.       int retval = -1 ;
  74.       int i = 0;
  75.       char subpath[128] = "";
  76.       while ( i < strlen(path)+1 ) {
  77.           if (path[i] == '\\' OR path[i] == '/' OR path[i] == '\0') 
  78.               retval = mkdir(subpath) ;
  79.           subpath[i] = path[i] ;
  80.           i++ ;
  81.       }
  82.       return(retval);
  83. }
  84.  
  85. int mkdir ( char *path){
  86.    int iRetVal;
  87.    _asm {
  88.            push dx
  89.            push ds
  90.            mov ah, 0x39
  91.            lds dx, [path]
  92.            int 21h
  93.            mov iRetVal,0
  94.            jnc mkdir1
  95.            mov iRetVal,AX
  96.        mkdir1:
  97.            pop ds
  98.            pop dx  
  99.    } 
  100.    return(iRetVal) ;
  101. }
  102.  
  103.  
  104.