Here are some of my extra file FN's:
They include all that is needed to open the temp folder, create a file, open its resource fork, kill the file and close its resource fork.
Have fun - and watch for the line breaks
David
'~'
' FN fndTempFile returns the working directory ref number of the
' System:Temporary Items folder. With the ref number, you can open any
' file in the folder by name with FB's OPEN statement. NOTE: This
' FN is SYSTEM 7 DEPENDENT.
' INPUTS: @ptr& - VAR: pointer to integer wdRefNum variable
' OUTPUT: osErr% - INTEGER: error code, 0 = no error
' GLOBALS: none
LOCAL MODE
LOCAL FN fndTempFile(@thePtr&)
dim osErr%, prefRef%
dim @pVRef%
dim @pDirID&
osErr% = FN FINDFOLDER(_kOnsystemdisk,_"temp",_zTrue,pVRef%,pDirID&)
LONG IF osErr% = _noErr
prefRef% = FN getWDRefNum(pDirID&,pVRef%)
POKE WORD thePtr&,prefRef%' return value to caller
END IF
END FN = osErr%
'~'
'~'
' Given a working directory reference number, FN getDirID returns
' that directory's unique long integer ID number.
' OK for Miniruntime: Yes
' INPUTS: wdRef% - INTEGER: working directory ID number
' OUTPUTS: ioDrDirID&- LONGINT: directory ID number
' GLOBALS: none
CLEAR LOCAL
LOCAL FN getDirID(wdRef%)
DIM pBlk.200
DIM 31 fldr$
dim osErr%
pBlk.ioNamePtr& = @fldr$
pBlk.ioVRefNum% = wdRef
pBlk.ioFDirIndex& = -1
osErr% = FN GETCATINFO(@pBlk)
END FN = pBlk.ioDrDirID&' 0 if not found
'~'
'~'
' FN moveFile takes a file identified by its name and working
' directory ID number (returned by FILES$), and moves it to
' the directory of your choice.
' OK for Miniruntime: Yes
' INPUTS: fName$ - STR31: target file name
' fRef% - INTEGER: target files working directory
' dRef% - INTEGER: destination working directory
' OUTPUTS: osErr% - INTEGER: HFS error code, 0 = no error
' GLOBALS: none
'LOCAL MODE
'CLEAR LOCAL
LOCAL FN moveFile(fName$,fRef%,dRef%)
DIM pBlk.220
dim osErr%
pBlk.ioNamePtr& = @fName$
pBlk.ioVRefNum% = -1
pBlk.ioDirID& = FN getDirID(fRef%)
pBlk.ioNewDirID& = FN getDirID(dRef%)
osErr% = FN PBCatMoveSync(@pBlk)
END FN = osErr%
'~'
'~'
/* Changes the name of an existing file */
LOCAL FN reNameFile (oldName$,newName$,fileWDNo)
DIM pBlk.200
'DIM 31 oldName$
'DIM 31 newName$
dim osErr%
pBlk.ioNamePtr& = @oldName$
pBlk.ioVRefNum% = fileWDNo
pBlk.ioFDirIndex& = -1
osErr% = FN GETCATINFO(@pBlk)
pBlk.ioNamePtr& = @newName$
osErr% = FN SETCATINFO(@pBlk)
END FN
'~'
'~'
/* Removes an existing Temporary file */
LOCAL FN killTemp (fileName$,ResRefNo)
dim osErr%,ok
dim @WDrefNo
osErr% = FN fndTempFile(WDrefNo)'get temp file WD
ok = FN fileExists(fileName$,WDrefNo)'check file exists
LONG IF ok = _ztrue
LONG IF osErr% = _NoErr
LONG IF ResRefNo
CALL CLOSERESFILE(ResRefNo)'close .temp resource file fork
ResRefNo = _False' set res ref no to 0
END IF
KILL fileName$,WDrefNo'kill .temp file
END IF
END IF
END FN = ResRefNo
'~'
'~'
/* Creates a temporary file in the Temporary items folder */
LOCAL FN makeTempFile (fileName$,theType$,theCreator$)
dim osErr%
dim @prefRef%
dim tempResRefNo
LONG IF SYSTEM(_sysVers) => 7'requires system 7
osErr% = FN fndTempFile(prefRef%)
LONG IF osErr% = _noErr
tempResRefNo = FN createNewResFile (fileName$,prefRef%,theType$,theType$)'create .temp Res
XELSE
FN pGshowErr (12)'error opening Temporary Folder
END IF
XELSE
FN pGshowErr (11)'system < 7 error
END IF
END FN = tempResRefNo
'~'
'~'
local fn createTemp
gTempResRefNo = FN makeTempFile (_TempName$,_type$,_creator$)'make a temp file
LONG IF gTempResRefNo = 0'problem creating temp file
gKissOfDeath = 1'terminate program as no Temp file created
END IF
end fn
'~'
--
-----------------------------------------------------------------------
Dr David Cottrell
School of Psychology
James Cook University
Let my words be as honey, for tomorrow I will probably have to eat them.
-----------------------------------------------------------------------