Hi all,
I would like to know how to filter files in a folder to show only a certain type of files (eg *.pdf, *.ico, *.log, etc.)?
Do I need to add a “File Type Group” with the extensions that interest me?
Is filtering files by Type (folderitem.Type) or by Extension the same thing?
Here is a basic example of code to adapt:
Var DeskFiles As FolderItem = SpecialFolder.Desktop
For Each Deskfile As FolderItem In Files.Children
Listbox1.AddRow(file.Name)
Next
Use an IF inside the loop, check desired properties, like IsFolder, or Type if you defined some in the project, or analyze the Name, skip or process accordingly your desired matches.
Var matches() As String
Var matchingTypes As String = "jpg/jpeg/png/gif/tif/tiff/htm/html/" // lower case, every extension ends with /
Var files As FolderItem = SpecialFolder.Desktop
For Each file As FolderItem In files.Children
If not file.IsFolder Then // Only files
Var getNameType() As String = file.Name.Split(".")
Var nameType As String = ""
If getNameType.LastIndex > 0 Then nameType = getNameType(getNameType.LastIndex).Lowercase // nametype = "jpg", "txt", etc
If nameType > "" And matchingTypes.IndexOf(nameType+"/") >= 0 Then
matches.Add file.Name // lets get only matching file extensions listed
End
End
Next
Break // here are the matches()