[futurebasic] Re: Listing Files in a folder (more)

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : June 1998 : Group Archive : Group : All Groups

From: "Deepesh Letap" <DLetap@...>
Date: Tue, 02 Jun 1998 19:34:38 +0100
>I've been meaning to ask a closely related question, and can't quite figure
>out how to apply the FILES$ command to this situation:
>
>I know the _location_ (a global prefsVol% which I've already got), the
>_filename_, and the _file type_ (but watch out! the file type _isn't_ the
file
>type created by my application).
>
>What's the cleanest way of simply checking whether the specified file,
and/or
>file of specified type, exists in the given location? I don't need to open
it
>or do anything with it, just look to see whether it's there.


Try the following function:


LOCAL FN FileCheckExist(FileName$,VolRefNum%)
  DIM ParamBlock.128
  ParamBlkPtr&=VARPTR(ParamBlock)
  DEF BLOCKFILL (ParamBlkPtr&,128,0)
  DoesExist%=_False
  ParamBlock.ioVRefNum  = VolRefNum%
  ParamBlock.ioNamePtr& = VARPTR(FileName$)
  osErr%=FN HGETFILEINFO(ParamBlkPtr&)
  LONG IF osErr%=_noErr
    ParamBlock.iocompletion% = _noErr
    DoesExist%=_True
  XELSE
    DoesExist%=_False
  END IF
END FN = DoesExist%



Call it using the following:


FileName$= "ThisIsMyFile"
VolRefNum%=prefsVol%
DoesExist%=FN FileCheckExist(FileName$,VolRefNum%)
LONG IF DoesExist%=_True
  PRINT "Yes, it exists"
XELSE
  PRINT "No, it does not exist"
END IF



Hope it helps,

Deep