Lanc1988 Posted February 23, 2004 Posted February 23, 2004 I have a listbox and it lists all the files in a directory, but for some reason it is displaying the file "thumbs.db" I went to the directory and I didnt see it but when I click it in the listbox it wants me to Open or Save it. So my question is, is there a way to hide a file from showing in the listbox? Or possible hiding all files ending in .db? Quote
TechnoTone Posted February 23, 2004 Posted February 23, 2004 "thumbs.db" is created by Windows XP. It contains thumbnail's of the images in that folder. The reason you can't see it normally is because it is a hidden system file. Are you populating the listbox manually from code? If so, you'll need to filter out hidden and system files so that they are not included. Quote TT (*_*) There are 10 types of people in this world; those that understand binary and those that don't.
Lanc1988 Posted February 23, 2004 Author Posted February 23, 2004 ok here is the code i am using to get the files from the directory: Dim Allfiles As String() = IO.Directory.GetFiles(Application.StartupPath & "\Sidekick Files\Image Viewer") Dim strfile As String For Each strfile In Allfiles Dim filename As New IO.FileInfo(strfile) 'This will give you the file name etc. ListBox1.Items.Add(filename.Name) Next 'Loads the Click a Image/Help page in browser. AxWebBrowser1.Navigate(Application.StartupPath & "\Sidekick Files\Click a Image.htm") So how would i go about adding code to that to make it filter out system and hidden files? Quote
*Experts* mutant Posted February 23, 2004 *Experts* Posted February 23, 2004 You can check attributes using the Attributes property provided by the FileInfo class. The enumaration has a System and Hidden members, just what you are looking for: Dim filename As New IO.FileInfo(strfile) 'if file is not system then add, do same for hidden but select the Hidden enum memmber rather than system If Not filename.Attributes = IO.FileAttributes.System Then ListBox1.Items.Add(filename.Name) End If Quote
Lanc1988 Posted February 23, 2004 Author Posted February 23, 2004 when i try to use that code you posted, it doesn't show any files but instead lists the folder name. Dim filename As New IO.FileInfo(Application.StartupPath & "\Sidekick Files\Image Viewer") If Not filename.Attributes = IO.FileAttributes.System Then ListBox1.Items.Add(filename.Name) End If Quote
*Experts* mutant Posted February 23, 2004 *Experts* Posted February 23, 2004 Are you sure? It works for me. And I forgot to add one thing, all files are created with the Archive atrribute so you have to add the Archive value to get the proper files. Quote
Lanc1988 Posted February 23, 2004 Author Posted February 23, 2004 Where/how do I add the archive value at? Quote
Lanc1988 Posted February 23, 2004 Author Posted February 23, 2004 does anyone know of a way where i could have it show files ending in certain types? The types would be .bmp and .jpg, but i would like to be able to add more types if i need to. Here is the code I am using for it now: Dim Allfiles As String() = IO.Directory.GetFiles(Application.StartupPath & "\Sidekick Files\Image Viewer") Dim strfile As String For Each strfile In Allfiles Dim filename As New IO.FileInfo(strfile) 'This will give you the file name etc. ListBox1.Items.Add(filename.Name) Next Quote
*Experts* mutant Posted February 24, 2004 *Experts* Posted February 24, 2004 (edited) The GetFiles method accepts a search pattern as second argument. You will probably have to do a call to GetFiles for each file type. Example pattern: "*.bmp" You can do something like this to include for the file attribute problem: 'include archive but not hidden Dim attrs As IO.FileAttributes = IO.FileAttributes.Archive And Not IO.FileAttributes.Hidden If filename.Attributes = attrs Then 'add file Edited February 24, 2004 by mutant Quote
Lanc1988 Posted February 25, 2004 Author Posted February 25, 2004 so would I add that to my code I have now? or replace my code with that? Quote
techmanbd Posted February 26, 2004 Posted February 26, 2004 Here is how you get the files up for certain types Dim strpath As String = "c:\somedirectory" Dim strfile As String Dim Allfiles As String() = IO.Directory.GetFiles(strpath, "*.bmp") For Each strfile In Allfiles Dim filename As New IO.FileInfo(strfile) ListBox1.Items.Add(filename.Name) Next Quote Live as if you were to die tomorrow. Learn as if you were to live forever. Gandhi
Lanc1988 Posted February 26, 2004 Author Posted February 26, 2004 ok, so would i just add commas after the "*.bmp" to add more types that can be in the listbox? Quote
Lanc1988 Posted February 26, 2004 Author Posted February 26, 2004 so what do I add to get more types of file extentions? like .jpg and .gif Quote
techmanbd Posted February 26, 2004 Posted February 26, 2004 Not sure, I tried the commas and it didn't work. What I did was just make another FOR EACH loop. So I have 2 FOR EACH loop. one does one type and the other does the other type. Quote Live as if you were to die tomorrow. Learn as if you were to live forever. Gandhi
Lanc1988 Posted February 26, 2004 Author Posted February 26, 2004 can you post that? how you did the loop.. Quote
techmanbd Posted February 26, 2004 Posted February 26, 2004 Dim strpath As String = "c:\somedirectory" Dim strfile As String Dim Allfiles As String() = IO.Directory.GetFiles(strpath, "*.bmp") For Each strfile In Allfiles Dim filename As New IO.FileInfo(strfile) ListBox1.Items.Add(filename.Name) Next Allfiles = IO.Directory.GetFiles(strpath, "*.jpg") For Each strfile In Allfiles Dim filename As New IO.FileInfo(strfile) ListBox1.Items.Add(filename.Name) Next Quote Live as if you were to die tomorrow. Learn as if you were to live forever. Gandhi
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.