Subname: WildCardFilesList2
Description: Is used to retrieve a list of files that match your wildcard selections from your selected folder/path.
This is an extended Sub based on WildCardFilesList. Thank you @margret for the inspiration. I found this on Stackoverflow and thought "Is that possible with B4A-regex? Let´s try". Here is the result
Dependencies/Libraries: None
Example:
Tags: Files, FileList, WildCard, File Type, ListFiles, Filtered File Types, Sorted, WildCards
V1.0 09/17/2014
============
- Initial release
V1.1 09/18/2014
============
- changed the generation of the pattern (thanks @Mahares for reporting the error)
Description: Is used to retrieve a list of files that match your wildcard selections from your selected folder/path.
This is an extended Sub based on WildCardFilesList. Thank you @margret for the inspiration. I found this on Stackoverflow and thought "Is that possible with B4A-regex? Let´s try". Here is the result
Dependencies/Libraries: None
B4X:
Sub WildCardFilesList2(FilesPath As String, WildCards As String, Sorted As Boolean, Ascending As Boolean) As List
If File.IsDirectory("", FilesPath) Then
Dim FilesFound As List = File.ListFiles(FilesPath)
Dim GetCards() As String = Regex.Split(",", WildCards)
Dim FilteredFiles As List : FilteredFiles.Initialize
For i = 0 To FilesFound.Size -1
For l = 0 To GetCards.Length -1
Dim TestItem As String = FilesFound.Get(i)
Dim mask As String = GetCards(l).Trim
Dim pattern As String = "^"&mask.Replace(".","\.").Replace("*",".+").Replace("?",".")&"$"
If Regex.IsMatch(pattern,TestItem) = True Then
FilteredFiles.Add(TestItem.Trim)
End If
Next
Next
If Sorted Then
FilteredFiles.SortCaseInsensitive(Ascending)
End If
Return FilteredFiles
Else
Msgbox("You must pass a valid Directory.", "NOTICE")
End If
End Sub
Example:
B4X:
Dim flist As List = WildCardFilesList2(File.DirRootExternal,"*.log.0, *.txt",True, True)
For i = 0 To flist.Size -1
Dim filename As String = flist.Get(i)
Log(flist.Get(i))
Next
Tags: Files, FileList, WildCard, File Type, ListFiles, Filtered File Types, Sorted, WildCards
V1.0 09/17/2014
============
- Initial release
V1.1 09/18/2014
============
- changed the generation of the pattern (thanks @Mahares for reporting the error)
Last edited: