[futurebasic] Re: [FB] Getting FSRef for file

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : April 2011 : Group Archive : Group : All Groups

From: Robert Purves <listrp@...>
Date: Tue, 26 Apr 2011 10:35:39 +1200
Warren Lanford wrote:

> Am trying to get FSRef for a file after using :
> newfilename$ = FILES$(_FSSpecSave,"Save Image As…",gFileNam$,fileSpec)
> I found and am trying to use the following to get info about the file before attempting to write to it.

If you want to stick with FSSpecs for the rest of your code, you may find it easier to use this test for locked status. It takes a FSSpec instead of FSRef.

Robert P.

'---------------
include "Tlbx MoreFilesX.incl"

local fn FSpCheckLock( spec as ^FSSpec ) as OSErr
'~'1
dim as OSErr          result
dim as FSRef          ref
dim as FSCatalogInfo  catalogInfo
dim as FSVolumeInfo   volumeInfo

// Get FSRef
result = fn FSpMakeFSRef( #spec, @ref )
long if ( result == _fnfErr ) // file doesn't exist
result = _noErr // not locked
exit fn
end if
// Get nodeFlags and FSVolumeRefNum
result = fn FSGetCatalogInfo( ref, _kFSCatInfoNodeFlags + _kFSCatInfoVolume, @catalogInfo, 0, 0, 0 )
if ( result ) then exit fn
long if ( catalogInfo.nodeFlags and _kFSNodeLockedMask )
result = _fLckdErr // File is locked
exit fn
end if
// File isn't locked, but is volume locked? Check volume flags.
result = fn FSGetVolumeInfo( catalogInfo.volume, 0, 0, _kFSVolInfoFlags, @volumeInfo, 0, 0 )
if ( result ) then exit fn
long if ( volumeInfo.flags and _kFSVolFlagHardwareLockedMask )
result = _wPrErr // Volume locked by hardware.
exit fn
end if
long if ( volumeInfo.flags and _kFSVolFlagSoftwareLockedMask )
result = _vLckdErr // Volume locked by software.
end if
end fn = result
'---------------