Microsoft KB Archive/69110

= QB 4.x Program Example to Create or Remove Directory =

Article ID: 69110

Article Last Modified on 8/16/2005

-

APPLIES TO


 * Microsoft QuickBasic 4.5 for MS-DOS
 * Microsoft QuickBasic 4.0
 * Microsoft QuickBASIC 4.0b

-



This article was previously published under Q69110



SUMMARY
In Microsoft Basic Professional Development System (PDS) versions 7.00 and 7.10, the statement to make a directory is MKDIR(Directory$), and the statement to remove a directory is RMDIR(Directory$). Because QuickBasic versions 4.00, 4.00b, and 4.50 do not have these statements, two alternative ways of creating and removing directories are listed below.

The following information applies to Microsoft QuickBasic versions 4.00, 4.00b, and 4.50 for MS-DOS.



MORE INFORMATION
The first method to either create or remove directories is simple, but requires more memory and is slower. This first method requires using the SHELL statement. Directory$ = &quot;Dir1&quot;  ' Put the new directory name to create here. Sh$ = &quot;MKDIR &quot;+ Directory$ SHELL Sh$            ' Creates a directory named Dir1. You could substitute &quot;RMDIR &quot; for &quot;MKDIR &quot; above to remove the directory.

Method two below uses a CALL INTERRUPT statement to make and remove directories. This method uses less memory and is faster because it does not do a SHELL. It also returns a code to tell you whether or not the operation was successful. ' MRDIR.BAS ' Example program to Make or Remove DIRectories. ' ' To run this program in QB.EXE, type the following at the DOS prompt: '     QB MRDIR /L ' Type in the program, and run it (SHIFT+F5).

DECLARE FUNCTION MakeDir% (Directory$) DECLARE FUNCTION RemoveDir% (Directory$)

' $INCLUDE: 'QB.BI' CLS PRINT &quot;1. Make a Directory&quot; PRINT &quot;2. Remove a Directory&quot; DO

C$ = INKEY$

LOOP UNTIL C$ = &quot;1&quot; OR C$ = &quot;2&quot; IF C$ = &quot;1&quot; THEN

INPUT &quot;Enter the name of the new directory &quot;, Directory$ x = MakeDir(Directory$)

ELSE

INPUT &quot;Enter the name of the directory to be removed &quot;,

Directory$

x = RemoveDir(Directory$)

END IF IF x = 0 THEN PRINT &quot;Successful&quot; ELSE PRINT &quot;Unsuccessful&quot;

' The following function creates a new subdirectory in the current ' directory. This function returns 0 if the directory was created ' successfully, or returns 1 if the directory could not be created.

FUNCTION MakeDir% (Directory$) DIM inreg AS RegType, outreg AS RegType IF RIGHT$(Directory$, 1) <> CHR$(0) THEN Directory$ = Directory$ + CHR$(0) END IF     inreg.ax = &H3900     'Function 39 hex of interrupt 21 hex. inreg.dx = SADD(Directory$)  'Offset of string variable. CALL INTERRUPT(&H21, inreg, outreg) MakeDir% = (outreg.flags AND 1)  'Return success flag.

END FUNCTION

' The following function deletes an existing subdirectory from the ' current directory. This function returns 0 if the directory was ' deleted successfully, or returns 1 if the directory could not be ' deleted.

FUNCTION RemoveDir% (Directory$) DIM inreg AS RegType, outreg AS RegType IF RIGHT$(Directory$, 1) <> CHR$(0) THEN Directory$ = Directory$ + CHR$(0) END IF     inreg.ax = &H3A00       'Function 3A hex of interrupt 21 hex. inreg.dx = SADD(Directory$) 'Offset of string variable. CALL INTERRUPT(&H21, inreg, outreg) RemoveDir% = (outreg.flags AND 1) 'Return success flag.

END FUNCTION

Additional query words: QuickBas

Keywords: KB69110

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.