Exclude files from being displayed in a FileView control

Post

Posted
Rating:
#1 (In Topic #678)
Trainee
 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
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Regular
cage is in the usergroup ‘Regular’
I found this example from the Gambas Buch that should help understanding the use of FileView.

Code (gambas)

  1. ' Gambas class file
  2.  
  3. Public sFileName As String
  4. Public aFileNames As String[]
  5.  
  6. Public Sub Form_Open()
  7.  
  8.   FMain.Resizable = False
  9.   DirBox1.Value = "/home/hans/BildTon" ' (Start-)Folder
  10.  
  11.   FileView1.Dir = DirBox1.Value
  12.   FileView1.IconSize = 32 ' Default-Value = 32
  13.   FileView1.ShowPreview = True
  14.   FileView1.ShowHidden = True
  15.   FileView1.Background = &HC3DDFF
  16.   FileView1.Foreground = Color.DarkGreen
  17.   FileView1.Mode = Select.Single
  18.  
  19.   'Note this is where you setup what files you wish to display.
  20.   'All others will not be show in the FileView.
  21.  
  22.   FileView1.Filter = ["*.txt", "*.png", "*.pd*", "*.jp*", "*.xml"]
  23.   Wait
  24.  
  25.   btnShowFileListContent.Enabled = False
  26.  
  27.  
  28. Public Sub FileView1_Click()
  29.  
  30.   Dim sFileDir, sFilePath As String
  31.  
  32.   sFileName = FileView1.Current
  33.   sFileDir = FileView1.Dir
  34.   sFilePath = sFileDir &/ sFileName
  35.  
  36.   lblFileName.Text = Subst("&1 &2 &3", ("Filename"), ":", sFileName)
  37.  
  38.  
  39. Public Sub FileView1_Select()  
  40.   If FileView1.Current Then
  41.      Print Subst("&1 '&2' &3", ("The file"), FileView1.Current, ("has been selected."))
  42.  
  43. Public Sub DirBox1_Click()
  44.   FileView1.Dir = DirBox1.Value
  45.  
  46. Public Sub btnSetMultiple_Click()
  47.  
  48.   If FileView1.Mode = Select.Single Then ' The default-value is "Single"
  49.      FileView1.Mode = Select.Multiple
  50.      btnSetMultiple.Caption = "Set file selection to single"
  51.      btnShowFileListContent.Enabled = True
  52.   Else
  53.      FileView1.Mode = Select.Single
  54.      btnSetMultiple.Caption = "Set file selection to multiple"
  55.      btnShowFileListContent.Enabled = False
  56.  
  57.  
  58. Public Sub btnShowFileListContent_Click()
  59.  
  60.   Dim sFile, sContent As String
  61.  
  62.   If FileView1.Mode = Select.Multiple Then
  63.      If FileView1.Selection.Count > 0 Then
  64.         lblFileName.Text = ""
  65.         aFileNames = FileView1.Selection
  66.         For Each sFile In aFileNames
  67.           sContent &= sFile & gb.Lf
  68.         Next
  69.         Message.Info("Selected files:<hr>" & sContent)
  70.         FileView1.UnselectAll()
  71.         FileView1.Mode = Select.Single
  72.         btnSetMultiple.Caption = "Set file selection to multiple"
  73.         btnShowFileListContent.Enabled = False
  74.      Endif

This is a lot of good information with Gambas-Buch at this website.
https://www.gambas-buch.de/doku.php

Hope this helps.
Online now: No Back to the top

Post

Posted
Rating:
#3
Avatar
Regular
stevedee is in the usergroup ‘Regular’

bazzvn said

… I specifically want to display all files in a directory EXCEPT "*.html" and "*.txt" files…

I would have expected to use something like this;

Code (gambas)

  1.   FileView1.Filter = ["^.txt,^.html, Most Files"]

…but I can't get it to work. Sorry.
Online now: No Back to the top

Post

Posted
Rating:
#4
Avatar
Regular
tincho is in the usergroup ‘Regular’

bazzvn said

 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

Code (gambas)

  1. Property Excuded As String[]
  2. '...
  3. Private Function CheckExcluded(sFile As String) As Boolean
  4.   Dim sExcluded As String
  5.   For Each sExcluded In $aExcluded
  6.     If sFile Like sExcluded Then Return
  7.   Next
But this implies made a new control.
Regards.
Online now: No Back to the top

Post

Posted
Rating:
#5
Guru
BruceSteers is in the usergroup ‘Guru’
does this work…
[EDITED]

Code (gambas)

  1.  
  2. FileView1.Filter = ["*[^\{.html}][^\{.txt}]"]
  3.  
  4.  

Also this…

Code (gambas)

  1.  
  2. FileView1.Filter = ["*[^\{.html,.txt}]"]
  3.  
  4.  

FileView uses gambas LIKE command so read here…

/lang/like - Gambas Documentation
Online now: No Back to the top

Post

Posted
Rating:
#6
Avatar
Regular
tincho is in the usergroup ‘Regular’

BruceSteers said

does this work…
[EDITED]

Ok, i was checking the previous proposal and there are some errors. This version works perfect !
it was…

Code (gambas)

  1. FileView1.Filter = ["*[^.csv][^.txt]"]
<IMG src="https://i.imgur.com/rwB71bV.png"> </IMG>
But now

Code (gambas)

  1. FileView1.Filter = ["*[^\{.csv},\{.txt}]"]
<IMG src="https://i.imgur.com/iopMM6B.png"> </IMG>
Online now: No Back to the top

Post

Posted
Rating:
#7
Guru
BruceSteers is in the usergroup ‘Guru’

tincho said

BruceSteers said

does this work…
[EDITED]

Ok, i was checking the previous proposal and there are some errors. This version works perfect !
it was…

Code (gambas)

  1. FileView1.Filter = ["*[^.csv][^.txt]"]
But now

Code (gambas)

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

Code (gambas)

  1. FileView1.Filter = ["*[^\{.csv,.txt}]"]
Online now: No Back to the top

Post

Posted
Rating:
#8
Guru
BruceSteers is in the usergroup ‘Guru’
Happy to show the way ;)  :lol:
Online now: No Back to the top

Post

Posted
Rating:
#9
Avatar
Guru
cogier is in the usergroup ‘Guru’
<LIST>
  • <LI>FileView1.Filter = ["*[^{.html,.txt}]"]</LI>
</LIST>
<LIST>
  • <LI>FileView1.Filter = ["*[^{.html}][^{.txt}]"]</LI>
</LIST>
<LIST>
  • <LI>FileView1.Filter = ["*[^{*.html,*.txt}]"]</LI>
</LIST>

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.
Online now: No Back to the top

Post

Posted
Rating:
#10
Avatar
Regular
tincho is in the usergroup ‘Regular’

cogier said

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.
Online now: No Back to the top

Post

Posted
Rating:
#11
Trainee
 Thank you everyone. I did a quick check and I can't get any of the solutions suggested by tincho, Bruce or cogier to work. As pointed out already, odt files are excluded and as it turns out, so too are Freeplane *.mm files. I didn't have time to explore further, but it seems files with extensions that share one of the characters in  'html' or 'txt" are also excluded.
Perhaps this is not such a simple question as originally thought. It will be a week or so before I have time to follow up.
Thanks again,
bazzvn
Online now: No Back to the top
1 guest and 0 members have just viewed this.