I’ve created a File Type Set which shows only particular files types for an Open Dialog - works as expected - but now I’d like to do similar with a list box.
This is the code I’m using to populate the listbox with files from a folder:
[code]
Dim myFolder As FolderItem = SpecialFolder.ApplicationData.Child(myAppDataFilesFolder)
If myFolder Is Nil Then
Return
End If
Dim filecount As Integer = myFolder.Count
For i As Integer = 1 To filecount
Dim f As FolderItem = myFolder.Item(i)
If f <> Nil Then
listSavedFiles.AddRow(f.Name)
End If
Next[/code]
This works as expected and displays ALL the files in that folder.
How do I go about only showing or populating the list with files of a certain type/extension?
I did try using the same File Type Set I created for the open dialog window but get errors.
type literally tells you “i recognize this file as this filetype you defined”
you can pretty much get away with checking for type <> “” since that will only be set if it matches one of the types you defined
If myFolder Is Nil Then
Return
End If
Dim filecount As Integer = myFolder.Count
For i As Integer = 1 To filecount
Dim f As FolderItem = myFolder.Item(i)
If f <> Nil and f.type <> "" Then // <<<<< might need to check for directories but nothing else
listSavedFiles.AddRow(f.Name)
End If
Next
No
Folderitem.Type is ONLY populated IF the file in question matches one of the FileTypes you defined
Otherwise the file is “unrecognized” and type is empty
Ahhh! Thanks Norman for your patience. I think “the penny has finally dropped”
I have two FileTypes that have global scope under the main window. The reason why only one FileType showed up in the list is because the other FileType wasn’t represented in the directory. I just tested this by changing one of the file extensions to the other FileType and then they both showed up in the list - as expected.