Exclude files from being displayed in a FileView control

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

Exclude files from being displayed in a FileView control

Post 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
cage
Posts: 123
Joined: Monday 2nd September 2019 5:47am
Location: Phoenix Arizona

Re: Exclude files from being displayed in a FileView control

Post 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.
User avatar
stevedee
Posts: 518
Joined: Monday 20th March 2017 6:06pm

Re: Exclude files from being displayed in a FileView control

Post 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.
User avatar
tincho
Posts: 57
Joined: Wednesday 10th July 2019 1:12pm

Re: Exclude files from being displayed in a FileView control

Post 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.
User avatar
BruceSteers
Posts: 1521
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Exclude files from being displayed in a FileView control

Post 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
If at first you don't succeed , try doing something differently.
BruceS
User avatar
tincho
Posts: 57
Joined: Wednesday 10th July 2019 1:12pm

Re: Exclude files from being displayed in a FileView control

Post 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]"]
Image
But now
FileView1.Filter = ["*[^{.csv},{.txt}]"]
Image
User avatar
BruceSteers
Posts: 1521
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Exclude files from being displayed in a FileView control

Post 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}]"]
If at first you don't succeed , try doing something differently.
BruceS
User avatar
BruceSteers
Posts: 1521
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Exclude files from being displayed in a FileView control

Post by BruceSteers »

Happy to show the way ;) :lol:
If at first you don't succeed , try doing something differently.
BruceS
User avatar
cogier
Site Admin
Posts: 1118
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Exclude files from being displayed in a FileView control

Post 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.
User avatar
tincho
Posts: 57
Joined: Wednesday 10th July 2019 1:12pm

Re: Exclude files from being displayed in a FileView control

Post 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.
Post Reply