[futurebasic] Re: [FB] Files In A Folder

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : May 2001 : Group Archive : Group : All Groups

From: Ian Mann <i.mann@...>
Date: Wed, 16 May 2001 10:06:59 +0000

Martin Fitzgibbons wrote:

> I remember some while back some discussion on accessing
> all the files in a particular folder.
>
> eg if a folder has 10 jpeg graphics in it I would like to be able
> Load and know the name of each of the files in the folder.
>
> Does anyone have the code from the discussion or something
> similar
>
> Martin
>
> --
> To unsubscribe, send ANY message to <futurebasic-unsubscribe@...>

Hi Martin,

This code is not really mine, its taken from a number of examples. All errors
and inefficiencies I claim for my own.

I am trying to find all files of type Mp3 or with the suffix MP3 in a folder.
I am then loading them into an XREF array so that I can hold data about them,
scroll and select etc.

Pass the name of the folder you want to search to fn GetFolderDirID&. Let me
know if you want a more generic chunk of code.

Regards

Ian

CLEAR LOCAL
dim indxCount%,osErr%,Count%, Result%, myErr%, bitrate%
dim Size&
dim scratch#
dim a$ as Str31
LOCAL FN SearchFolder (@pbPtr&, dirID&,MainVRefNum%)
indxCount% = 1
DO
pbPtr&.ioFDirIndex%  = indxCount
pbPtr&.ioDirID&      = dirID&
osErr% = FN GETCATINFO (pbPtr&)
LONG IF osErr% = _noErr
LONG IF pbPtr&.ioFlAttrib% and 4096
inc(gFolderCount%)
gFolderNames$ (gFolderCount%) = pstr$(pbPtr&.ioNamePtr&)
osErr% = FN SearchFolder (=pbPtr&, pbPtr&.ioDirID& ,MainVRefNum%)
XELSE
Result% = _False
long if pbPtr&.ioFlUsrWds.fdType&     =  _"Mp3 "' Change for JPEG
Result% = _True
xelse
a$ = pstr$(pbPtr&.ioNamePtr&)
if Ucase$(right$(a$,4)) = ".MP3" then Result% = _True
end if
long if Result% = _True
inc(gTotalTracks)
Size& = (gTotalTracks + 1) * SIZEOF(Mp3Record)
syserror = _noErr
FN SETHANDLESIZE(MP3&,Size&)
myErr% = syserror
long if gTotalTracks <= gMaxTracks and myErr% = _noErr
MP3.Artist$(gTotalTracks) = gFolderNames$ (gFolderCount%)
MP3.Title$(gTotalTracks) = pstr$(pbPtr&.ioNamePtr&)
MP3.Mp3PathName$(gTotalTracks) = ""
MP3.Mp3VolName$(gTotalTracks) = gVolumeNames$ (gVolumeCount%)
MP3.MP3VolRefNum%(gTotalTracks) = MainVRefNum%
for Count% = 1 to gFolderCount%
MP3.Mp3PathName$(gTotalTracks) = MP3.Mp3PathName$(gTotalTracks) +
gFolderNames$ (Count%) + ":"
next
bitrate% = fn GetFirstMp3BitRate (MP3.Title$(gTotalTracks),folder
(MP3.Mp3PathName$(gTotalTracks),0))
scratch# = 128\bitrate%
MP3.FileSize&(gTotalTracks) = int(scratch# *
pbPtr&.iofllglen&/10000*.6*1.0483)
xelse
dec(gTotalTracks)
inc(gTracksNotAdded)
end if
end if
END IF
xelse
dec(gFolderCount%)
END IF
INC (indxCount%)
long if Fn tickcount > (gCurTicks& + _TicksBetweenCursor)
def cycle (_FirstRadioActiveCursor,_LastRadioActiveCursor,gCursor%)
gCurTicks& = fn tickcount
Cursor gCursor%
end if
UNTIL osErr% OR FN CheckKeys% (_EscapeKey)

END FN = (osErr% == _zTrue)

clear Local
dim DirID&
dim vRefNum%, OSErr%
DIM pbBlock.128
DIM 63 itemName$
local fn GetFolderDirID& (FolderName$)
vRefNum% = folder (FolderName$,0)
long if vRefNum% <> 0
pbBlock.ioNamePtr&      = @FolderName$'put pointer to dirName$
pbBlock.ioVRefNum%      = vRefNum%'set vRefNun
pbBlock.ioDrParID&      = [_curDirStore]'get current directory ID
pbBlock.ioFDirIndex%    = -1'get info on folder
OSErr% = FN GETCATINFO (@pbBlock)
long if OSErr% = _noErr
DirID& = pbBlock.ioDirID&
pbBlock.ioNamePtr&      = @itemName$
FN SearchFolder (pbBlock, DirID&,vRefNum%)
end if
end if
end fn = DirID&