[EMAIL PROTECTED] wrote:
Subject: Filtering by FileType?
From: Phil M <[EMAIL PROTECTED]>
Date: Wed, 15 Mar 2006 09:04:09 -0800
Since we are on the subject of file types, how do you determine if
any given FolderItem is of a particular file type?
Say for example, I have a FileType set of ImageTypes with TIFF, GIF,
JPEG, etc... how can I list all files in a directory that are of one
of the defined ImageTypes?
Note that is this *not* through an Open dialog, but would probably be
displayed in a Listbox.
Warning: the Case syntax works with REALbasic 2005r4...
Dim FldrFI As FolderItem // The target FolderItem
Dim FldrChild As FolderItem // The current item, Child of FldrFI
Dim fCnt As Integer // The # of items in FldrFI
Dim Idx As Integer // The loop indice
// For the example
FldrFI = SelectFolder
// Get the # of items in the choosed folder
fCnt = FldrFI.Count
If FldrFI Is Nil Then
// Do nothing...
Else // I’ve got a job!
// Scan all items in the choosed folder
For Idx = 1 To fCnt
// Get a Child Item
FldrChild = FldrFI.TrueItem(Idx)
// Make a 'sort'
Select Case FldrChild.Type
Case "image/bmp", "image/gif", "image/jpg", "image/png", "image/pict",
"image/tiff"
// Good guess! Add its display name to the LBReport ListBox
LBReport.AddRow FldrChild.DisplayName
Else
// Wrong type pal
LBReport.AddRow "Rejected"
End Select
// Avoid infinite loop
If UserCancelled Then Exit
Next
End If
REALbasic 2005r4 Pro for Mac OS
Tested with Mac OS X 10.3.9
in my current project (a FileType is defined and holds all 6 Mime used above)
The Mimes used in the Case are defined in the GraphicsFT File Types
LBReport is the name of the ListBox
... and I got one Rejected entry (.DS_Store file ?), all other files are .gif
(Popeye daily strips).
HTH,
Emile
PS: this code have been tested and works fine...
Example of file type defined in GraphicsFT:
DisplayName: image/bmp <that is what I called Mime earlier>
ObjectName: BMP
MacType: BMPf
MacCreator: <empty>
Extensions: .bmp
Icon: <empty>
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>