Futurebasic/Language/Reference/usr scanfolder

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Syntax[edit | edit source]

USR SCANFOLDER

Revised[edit | edit source]

FEBRUARY, 2002 (Release 6)

Description[edit | edit source]

In order to use this function, you must first create a file scan record. The format for this record can be found in the "Util_Files.incl" header and is as follows:

 BEGIN RECORD FileScanRec
 DIM ScanSpecAS FSSpec ' 70 bytes
 DIM ScanIndex AS LONG ' File Index
 DIM TypeAS OSTYPE ' File Type
 DIM CreatorAS OSTYPE ' Creator Type
 DIM DataLenAS LONG ' Data Fork Size
 DIM RsrcLenAS LONG ' Resource Fork Size
 DIM CDateAS LONG ' Creation Date
 DIM MDateAS LONG ' Modification Date
 DIM BDateAS LONG ' Backup Date
 DIM FndrLocAS LONG ' Finder Location
 DIM FndrFlags AS WORD ' File Flags
 DIM FileAttrAS WORD ' File Attributes
 DIM recursive AS WORD ' True if recursive scan
 END RECORD 

You dimension such a record like this:

 DIM myFileScanRecord AS FileScanRec 

To begin a scan, you will need to set up a couple of values in the scan record. The first is the FSSpec portion of the record, the second is the index which starts at zero for the first file in a folder.

 DIM fsr AS FileScanRec
 fsr.ScanIndex = 0
 fsr.ScanSpec = myFSSpecRec 

Each time this statement is executed, the ScanIndex value is incremented and information from the next file in the list is extracted. It is not necessary to manually handle this value, but it is possible to do so when desired.

Detecting Folders:

If the scanning process detects a folder, the result code of 1 is returned and the file type is set to _"fldr". You may use subsequent calls of USR SCANFOLDER to examine embedded folders. If you make these recursive calls, be sure to set the recursive field of the FileScanRec to _zTrue.

Example:

The following example lets the user select a folder using FILES$. Then all of the files in the same folder (along with some of the information contained in the FileScanRec) are displayed. The example first demonstrates a non recursive folder search and then a recursive folder search.

include "Util_Files.incl"

local fn ScanIt( fs as ^FSSpec, recursive as Boolean )
dim as FileScanRec fsr

fsr.scanIndex = 0
fsr.recursive = recursive
do
fsr.scanSpec = fs
select usr ScanFolder( fsr )
case 0 // file
long if fsr.fndrFlags and _fInvisible
print fsr.scanIndex, "Not Visible"
xelse
print fsr.scanIndex, mki$( fsr.type ), 
print fsr.dataLen, fsr.scanSpec.name
end if
case 1 // folder
print fsr.scanIndex, mki$( fsr.type ),, fsr.scanSpec.name
if ( recursive ) then fn ScanIt( fsr.scanSpec, _zTrue )
case else // error
exit do
end select
until 0
end fn

dim as FSSpec fs
window 1,, (0, 0)-(500, 800)
long if ( files$( _FSSpecFolder, "", "", fs ) )
fn ScanIt( fs, _false )
print "-----"
fn ScanIt( fs, _zTrue )
end if
do
HandleEvents
until gFBQuit

See Also[edit | edit source]

FILES$; RENAME; USR MOVEFILE; USR COPYFILE