[futurebasic] Re: [FB] FN folderExists%(fldrName$,inThisWDrefNum%)

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : December 1999 : Group Archive : Group : All Groups

From: Rick Brown <rbrown@...>
Date: Mon, 13 Dec 1999 20:48:39 -0600

Michael Evans wrote:

> FB II provides FN fileExists(fName$,fVol) which checks for the existence of
> a file named "fName$" in a folder whose WDrefNum% = fVol.
>
> To check for the existence of a folder named "fldrName$" in a folder whose
> WDrefNum% = inThisWDrefNum%, I came up with:
>
> (* function snipped *)

>
> Is there a faster or more sensible way of doing this not using FILES$?
>

I would use FN GETCATINFO to do it.  That will tell you (a) whether the named
item exists and (b) (if it exists) whether it's a file or a folder.  I assume
that you want to return _false in cases where the named item exists but it's a
file.

LOCAL FN FolderExists(fldrName$,inThisWDrefNum%)
  DIM pb.108, OSErr, itemExists, itsAFolder
  pb.ioNamePtr& = @fldrName$
  pb.ioVRefNum% = inThisWDrefNum%
  pb.ioDirID& = 0
  pb.ioDirIndex% = 0
  OSErr = FN GETCATINFO(@pb)
  itemExists = (OSErr = _noErr)
  itsAFolder = ((PEEK(@pb.ioFlAttrib) AND BIT(4)) <> 0)
END FN = itemExists AND itsAFolder

- Rick