How to Use HFSDispatch to Create a Macintosh Folder (36392)
This article was previously published under Q36392
SUMMARY
This article contains a sample program that demonstrates how to use
HFSDispatch to create a folder with Microsoft QuickBASIC version 1.00
for the Apple Macintosh.
MORE INFORMATION
The program below will create a new folder. If no volume or path is
specified, the folder is placed in the current folder on the current
volume. If a path is specified, it must be a full pathname, including
volume name and parent folder names. The last folder name in the path
specification is the one that will be created; all others in the path
must already exist.
If there is an error creating the folder, the error code will be
returned in the variable ErrCode%. The error codes are as follows:
0 No error, folder was created
1 Volume specified is not currently mounted
Other Error in creating the folder. This is the error code returned
by the PBDirCreate ROM routine. See "Inside Macintosh," Volume
4 for more information about these error codes.
This program creates the folder by properly establishing a parameter
block (stored here in IOPB%()), and making a call to HFSDispatch, call
number 6. For more information regarding the I/O Parameter Block
(IOPB), see "Inside Macintosh", Volume 4.
The following is a code example:
'--------------------------------------------------------
' DirCreate
' Copyright 1988 Microsoft Corp.
'
' This program is for personal use only. It may not be
' redistributed in any form, electronic or mechanical, for any
' purpose, without the written permission of Microsoft Corp.
'
'--------------------------------------------------------
'
' Subprogram which will create the specified folder name on
' either the current volume (in the current folder) or on the
' specified volume (in the specified folder).
'
'--------------------------------------------------------
INPUT "Please enter the folder to create:",fld$
DirCreate fld$, ECode%
WHILE MOUSE(0)<>1:WEND
END
SUB DirCreate (FolderName$, ErrCode%) STATIC
DIM IOPB%(120)
IF INSTR(FolderName$,":") = 0 THEN
' Set up for current volume/folder
Ptr& = &H352 'pointer to default VCB
Vol& = PEEKL(Ptr&) 'Default VCB
vRefNum% = PEEKW(Vol& + 78) 'Volume reference number
path$ = ""
GetDirName vRefNum%, path$
NewFolder$ = path$ + ":"+FolderName$
ELSE 'Entire volume:path specified
Vol$ = LEFT$(FolderName$, INSTR(FolderName$,":")-1)
Ptr& = &H358 'first VCB
Vol& = PEEKL(Ptr&)
Found% = 0
WHILE Vol& <> 0 AND Found% = 0
Vol& = PEEKL(Ptr&)
Ptr& = Vol&
IF Vol& <> 0 THEN
DirID& = 0 : n$ = ""
vRefNum% = PEEKW(Vol& + 78)
GetCatInfo IOPB%(0),n$,DirID&, vRefNum%
IF UCASE$(n$) = UCASE$(Vol$) THEN Found% = 1
END IF
WEND
IF Found% = 0 THEN
PRINT "Volume not mounted!"
ErrCode% = 1
EXIT SUB
END IF
NewFolder$ = FolderName$
END IF
pasFolder$ = ""
B2PStr NewFolder$, pasFolder$
POKEW VARPTR(IOPB%(0))+22, vRefNum%
POKEL VARPTR(IOPB%(0))+18, SADD(pasFolder$)
HFSDispatch 6,IOPB%(0)
ErrCode% = PEEKW(VARPTR(IOPB%(0))+16)
END SUB
Modification Type: |
Minor |
Last Reviewed: |
1/9/2003 |
Keywords: |
KB36392 |
|