A simple, perhaps naive question. I can see how to use the filter property to display selected types of files in a FileView control. But how do you exclude certain files from being displayed? I specifically want to display all files in a directory EXCEPT "*.html" and "*.txt" files.
Thanks,
bazzvn
Exclude files from being displayed in a FileView control
Re: Exclude files from being displayed in a FileView control
I found this example from the Gambas Buch that should help understanding the use of FileView.
https://www.gambas-buch.de/doku.php
Hope this helps.
' Gambas class file
Public sFileName As String
Public aFileNames As String[]
Public Sub Form_Open()
FMain.Resizable = False
DirBox1.Value = "/home/hans/BildTon" ' (Start-)Folder
FileView1.Dir = DirBox1.Value
FileView1.IconSize = 32 ' Default-Value = 32
FileView1.ShowPreview = True
FileView1.ShowHidden = True
FileView1.Background = &HC3DDFF
FileView1.Foreground = Color.DarkGreen
FileView1.Mode = Select.Single
'Note this is where you setup what files you wish to display.
'All others will not be show in the FileView.
FileView1.Filter = ["*.txt", "*.png", "*.pd*", "*.jp*", "*.xml"]
Wait
btnShowFileListContent.Enabled = False
End
Public Sub FileView1_Click()
Dim sFileDir, sFilePath As String
sFileName = FileView1.Current
sFileDir = FileView1.Dir
sFilePath = sFileDir &/ sFileName
lblFileName.Text = Subst("&1 &2 &3", ("Filename"), ":", sFileName)
End
Public Sub FileView1_Select()
If FileView1.Current Then
Print Subst("&1 '&2' &3", ("The file"), FileView1.Current, ("has been selected."))
Endif
End
Public Sub DirBox1_Click()
FileView1.Dir = DirBox1.Value
End
Public Sub btnSetMultiple_Click()
If FileView1.Mode = Select.Single Then ' The default-value is "Single"
FileView1.Mode = Select.Multiple
btnSetMultiple.Caption = "Set file selection to single"
btnShowFileListContent.Enabled = True
Else
FileView1.Mode = Select.Single
btnSetMultiple.Caption = "Set file selection to multiple"
btnShowFileListContent.Enabled = False
Endif
End
Public Sub btnShowFileListContent_Click()
Dim sFile, sContent As String
If FileView1.Mode = Select.Multiple Then
If FileView1.Selection.Count > 0 Then
lblFileName.Text = ""
aFileNames = FileView1.Selection
For Each sFile In aFileNames
sContent &= sFile & gb.Lf
Next
Message.Info("Selected files:<hr>" & sContent)
FileView1.UnselectAll()
FileView1.Mode = Select.Single
btnSetMultiple.Caption = "Set file selection to multiple"
btnShowFileListContent.Enabled = False
Endif
Endif
End
This is a lot of good information with Gambas-Buch at this website.https://www.gambas-buch.de/doku.php
Hope this helps.
Re: Exclude files from being displayed in a FileView control
I try to filter, but not success
maybe altering the class FileView.class adding
Property Excuded As String[]
'...
Private Function CheckExcluded(sFile As String) As Boolean
Dim sExcluded As String
For Each sExcluded In $aExcluded
If sFile Like sExcluded Then Return
Next
Return True
End
But this implies made a new control.Regards.
- BruceSteers
- Posts: 1575
- Joined: Thursday 23rd July 2020 5:20pm
- Location: Isle of Wight
- Contact:
Re: Exclude files from being displayed in a FileView control
does this work...
[EDITED]
http://gambaswiki.org/wiki/lang/like
[EDITED]
FileView1.Filter = ["*[^{.html}][^{.txt}]"]
Also this...
FileView1.Filter = ["*[^{.html,.txt}]"]
FileView uses gambas LIKE command so read here...http://gambaswiki.org/wiki/lang/like
If at first you don't succeed , try doing something differently.
BruceS
BruceS
Re: Exclude files from being displayed in a FileView control
Ok, i was checking the previous proposal and there are some errors. This version works perfect !
it was...
FileView1.Filter = ["*[^.csv][^.txt]"]
But now
FileView1.Filter = ["*[^{.csv},{.txt}]"]
- BruceSteers
- Posts: 1575
- Joined: Thursday 23rd July 2020 5:20pm
- Location: Isle of Wight
- Contact:
Re: Exclude files from being displayed in a FileView control
yes i realised after reading the LIKE wiki that it needed the {curly braces}
i think you use too many in your different copy of mine.
FileView1.Filter = ["*[^{.csv,.txt}]"]
If at first you don't succeed , try doing something differently.
BruceS
BruceS
- BruceSteers
- Posts: 1575
- Joined: Thursday 23rd July 2020 5:20pm
- Location: Isle of Wight
- Contact:
Re: Exclude files from being displayed in a FileView control
Happy to show the way
If at first you don't succeed , try doing something differently.
BruceS
BruceS
- cogier
- Site Admin
- Posts: 1126
- Joined: Wednesday 21st September 2016 2:22pm
- Location: Guernsey, Channel Islands
Re: Exclude files from being displayed in a FileView control
- FileView1.Filter = ["*[^{.html,.txt}]"]
- FileView1.Filter = ["*[^{.html}][^{.txt}]"]
- FileView1.Filter = ["*[^{*.html,*.txt}]"]
Re: Exclude files from being displayed in a FileView control
Filter it because .txt has the letter "t" and .odt also, which indicates that something is not right in this way of filtering.
I checked by changing .txt to .csv and in that case the .odt file is not filtered.
It also does not work properly when there are uppercase extensions.
Regards.