Exclude files from being displayed in a FileView control

Post your Gambas programming questions here.
bazzvn
Posts: 9
Joined: Wednesday 22nd February 2017 11:06am
Location: Vietnam

Exclude files from being displayed in a FileView control

Post by bazzvn » Sunday 30th May 2021 9:06am

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

cage
Posts: 97
Joined: Monday 02nd September 2019 5:47am
Location: Phoenix Arizona

Re: Exclude files from being displayed in a FileView control

Post by cage » Monday 31st May 2021 8:30pm

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.

User avatar
stevedee
Posts: 446
Joined: Monday 20th March 2017 6:06pm

Re: Exclude files from being displayed in a FileView control

Post by stevedee » Tuesday 01st June 2021 6:47am

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.

User avatar
tincho
Posts: 41
Joined: Wednesday 10th July 2019 1:12pm

Re: Exclude files from being displayed in a FileView control

Post by tincho » Tuesday 01st June 2021 9:41am

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.

User avatar
BruceSteers
Posts: 524
Joined: Thursday 23rd July 2020 5:20pm

Re: Exclude files from being displayed in a FileView control

Post by BruceSteers » Tuesday 01st June 2021 9:49am

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
Wishing well
Bruce

If at first you don't succeed , try it differently.

User avatar
tincho
Posts: 41
Joined: Wednesday 10th July 2019 1:12pm

Re: Exclude files from being displayed in a FileView control

Post by tincho » Tuesday 01st June 2021 11:55am

BruceSteers wrote:
Tuesday 01st 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]"]
Image
But now
FileView1.Filter = ["*[^{.csv},{.txt}]"]
Image

User avatar
BruceSteers
Posts: 524
Joined: Thursday 23rd July 2020 5:20pm

Re: Exclude files from being displayed in a FileView control

Post by BruceSteers » Tuesday 01st June 2021 12:15pm

tincho wrote:
Tuesday 01st June 2021 11:55am
BruceSteers wrote:
Tuesday 01st 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}]"]
Wishing well
Bruce

If at first you don't succeed , try it differently.

User avatar
BruceSteers
Posts: 524
Joined: Thursday 23rd July 2020 5:20pm

Re: Exclude files from being displayed in a FileView control

Post by BruceSteers » Tuesday 01st June 2021 12:16pm

Happy to show the way ;) :lol:
Wishing well
Bruce

If at first you don't succeed , try it differently.

User avatar
cogier
Site Admin
Posts: 721
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Exclude files from being displayed in a FileView control

Post by cogier » Tuesday 01st June 2021 2:18pm

  • 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.

User avatar
tincho
Posts: 41
Joined: Wednesday 10th July 2019 1:12pm

Re: Exclude files from being displayed in a FileView control

Post by tincho » Tuesday 01st June 2021 7:11pm

cogier wrote:
Tuesday 01st 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.

Post Reply