Page 1 of 2
Exclude files from being displayed in a FileView control
Posted: Sunday 30th May 2021 9:06am
by bazzvn
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
Re: Exclude files from being displayed in a FileView control
Posted: Monday 31st May 2021 8:30pm
by cage
I found this example from the Gambas Buch that should help understanding the use of FileView.
' 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
Posted: Tuesday 1st June 2021 6:47am
by stevedee
bazzvn wrote: ↑Sunday 30th May 2021 9:06am
... I specifically want to display all files in a directory EXCEPT "*.html" and "*.txt" files...
I would have expected to use something like this;
FileView1.Filter = ["^.txt,^.html, Most Files"]
...but I can't get it to work. Sorry.
Re: Exclude files from being displayed in a FileView control
Posted: Tuesday 1st June 2021 9:41am
by tincho
bazzvn wrote: ↑Sunday 30th May 2021 9:06am I specifically want to display all files in a directory EXCEPT "*.html" and "*.txt" files
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.
Re: Exclude files from being displayed in a FileView control
Posted: Tuesday 1st June 2021 9:49am
by BruceSteers
does this work...
[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
Re: Exclude files from being displayed in a FileView control
Posted: Tuesday 1st June 2021 11:55am
by tincho
BruceSteers wrote: ↑Tuesday 1st June 2021 9:49am
does this work...
[EDITED]
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}]"]
Re: Exclude files from being displayed in a FileView control
Posted: Tuesday 1st June 2021 12:15pm
by BruceSteers
tincho wrote: ↑Tuesday 1st June 2021 11:55am
BruceSteers wrote: ↑Tuesday 1st June 2021 9:49am
does this work...
[EDITED]
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}]"]
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}]"]
Re: Exclude files from being displayed in a FileView control
Posted: Tuesday 1st June 2021 12:16pm
by BruceSteers
Happy to show the way
Re: Exclude files from being displayed in a FileView control
Posted: Tuesday 1st June 2021 2:18pm
by cogier
- FileView1.Filter = ["*[^{.html,.txt}]"]
- FileView1.Filter = ["*[^{.html}][^{.txt}]"]
- FileView1.Filter = ["*[^{*.html,*.txt}]"]
I have done a little testing and found that all the proposed Filters above will hide
.odt files as well, I'm not sure why.
Re: Exclude files from being displayed in a FileView control
Posted: Tuesday 1st June 2021 7:11pm
by tincho
cogier wrote: ↑Tuesday 1st June 2021 2:18pm
I have done a little testing and found that all the proposed Filters above will hide
.odt files as well, I'm not sure why.
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.