home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 24 / CD_ASCQ_24_0995.iso / vrac / homonlib.zip / MAKEDIR.BAS < prev    next >
BASIC Source File  |  1995-04-13  |  3KB  |  91 lines

  1. DEFINT A-Z
  2.  
  3. ' $INCLUDE: 'TRUEFALS.INC'
  4.  
  5. DECLARE FUNCTION MakeDir (directory$)
  6.  
  7.  
  8. 'External procedures:
  9.  
  10. DECLARE FUNCTION DirExist (directory$)
  11.  
  12.  
  13. 'Error handling:
  14.  
  15. DIM SHARED ecode
  16.  
  17. MDErr:
  18.      ecode = ERR
  19.      RESUME NEXT
  20.  
  21. FUNCTION MakeDir (directory$)
  22. '****************************************************************************
  23. 'Creates a DOS directory.  Unlike the MKDIR command, MakeDir() can create a
  24. ' directory more than one level deep or on a different drive.
  25. '
  26. 'The directory$ argument may be passed with or without a trailing backslash.
  27. '
  28. 'Returns TRUE if successful, FALSE if unable to create the directory.  If
  29. ' unable to create the directory, MakeDir() DOES NOT clean up after itself by
  30. ' removing any partially created subdirectories.
  31. '
  32. 'If creating a multi-level subdirectory, it is best to pass the whole
  33. ' pathname, including the drive letter.
  34. '
  35. 'Examples:  MakeDir("GAMES")  Creates a subdirectory "GAMES" off the current
  36. '                             directory.
  37. '
  38. '           MakeDir("C:\SCIENCE\DATA")  Creates the specified directory. If
  39. '                                       the \SCIENCE directory doesn't exist,
  40. '                                       it will get created too.  This would
  41. '                                       crash the MKDIR command.
  42. '
  43. 'Note: MUST be compiled with the /X switch due to the RESUME NEXT stuff.
  44. '
  45. 'Caution: If using MakeDir() on a floppy drive, MAKE SURE that there is a
  46. ' diskette in the drive or your computer will hang.
  47. '
  48. '****************************************************************************
  49.  
  50. d$ = directory$                    'Use a temporary variable.
  51.  
  52. IF DirExist(d$) THEN               'If it already exists, return TRUE and
  53.      MakeDir = TRUE                'take credit for creating it!  This works
  54.      EXIT FUNCTION                 'for a null string too.
  55. END IF
  56.  
  57. bs$ = "\"
  58.  
  59. IF RIGHT$(d$, 1) = bs$ THEN        'Remove the trailing backslash, if any.
  60.      d$ = LEFT$(d$, LEN(d$) - 1)
  61. END IF
  62.  
  63. FOR x = 1 TO LEN(d$)               'Go through the new path one subdirectory
  64.      c$ = MID$(d$, x, 1)           'at a time until the whole thing exists.
  65.      IF c$ = bs$ THEN
  66.           IF NOT DirExist(subdir$) THEN
  67.                GOSUB MakeOne
  68.           END IF
  69.      END IF
  70.      subdir$ = subdir$ + c$
  71. NEXT x
  72.  
  73. GOSUB MakeOne                      'This is the final one! (subdir$ = d$)
  74.  
  75. MakeDir = TRUE                     'Everything went Ok to get to this point.
  76.  
  77. EXIT FUNCTION                      'Avoid a RETURN WITHOUT GOSUB error!
  78.  
  79.  
  80. MakeOne:
  81.  
  82.      ON ERROR GOTO MDErr           'We can never assume that the user of the
  83.      MKDIR subdir$                 'program has a clue and didn't just type
  84.      ON ERROR GOTO 0               'a bunch of garbage at the input prompt
  85.      IF ecode THEN EXIT FUNCTION   'that might choke the MKDIR command.
  86.      RETURN                        '(As a rule, you should edit user input
  87.                                    'before doing anything important with it.)
  88.  
  89. END FUNCTION
  90.  
  91.