Strange hidden file

tcross

Member
Joined
Oct 26, 2006
Messages
10
Programming Experience
1-3
Hello

I am using the code below to read and display that contents of a directory to a list box. It works great except it displays a file which I can't see or erase using Windows explorer. The file is called "thumbs.db" and I know it got in the directory when copying from a thumb drive. It is not just a hidden file because I have those also and know how to view and erase standard hidden files.

Does anyone know how to either erase this file or stop the VB.net code from displaying this type of file?

PrivateSub GetDirectoryContents()
Dim dDir AsNew DirectoryInfo(sDir)
Dim fFileSystemInfo As FileSystemInfo
ForEach fFileSystemInfo In dDir.GetFileSystemInfos()
Me.xFilesListBox.Items.Add(fFileSystemInfo.Name)
Next
EndSub

Thanks
 
Just solved this

I just fixed this by creating a new directory and copying all the visible files into it and erasing the old directory.
 
Thumbs.db is a file that XP+ used to store thumbnail images of all pictures in the folder.

The simplest way to avoid it with your code would be in your For Each event, simply check the file type and exclude "*.db" files. (Please note a few chanages I made to your code)

VB.NET:
Imports System.IO
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Me.GetDirectoryContents("C:\Documents and Settings\Knight\My Documents\My Pictures")

    End Sub
    Private Sub GetDirectoryContents(ByVal sDir As String)
        Dim dDir As New DirectoryInfo(sDir)
        Dim fFileInfo As FileInfo
        For Each fFileInfo In dDir.GetFiles
            If Not fFileInfo.Extension = ".db" Then
                Me.xFilesListBox.Items.Add(fFileInfo.Name)
            End If
        Next
    End Sub
End Class
 
I just fixed this by creating a new directory and copying all the visible files into it and erasing the old directory.


Just note that file will come back (or can) when the images are viewed again in explorer, so you should put the code in place to skip over it when it appears. You can use that same code I gave to go father, in the even you need to exclude other things like txt files or exe, etc that are in the folder.
 
Back
Top