vb.net FileInfo not listing correctly

I wrote some code that simple cleans out a users temporary internet cache, however it does not want to list out on the console all the files in the directory.  However if i change the directory to non hidden directory it works fine.  any ideas?  obviously username is in place of a username i would type in during testing.
My.Application.DoEvents()
        Dim DSPath As String = "C:\Documents and settings\username\local settings\temporary internet files"
        'Dim DSPath As String = "C:\Documents and Settings\" & GetUsername(My.User.Name) & "\Local Settings\Temporary Internet Files"
        Dim DS As New System.IO.DirectoryInfo(DSPath)
        Dim FI As System.IO.FileInfo

        Console.WriteLine(FIA.Length)
        For Each FI In DS.GetFiles
            Me.TBStatus.Text = "Cleaning Cookies: " & FI.FullName
            Console.WriteLine(FI.FullName)
        Next

Open in new window

LVL 3
beaconlightboyAsked:
Who is Participating?
 
käµfm³d 👽Connect With a Mentor Commented:
The reason you are not deleting all of the files with your original code is that even though Windows Explorer shows everything as an individual file within the Temporary Internet Files folder, the files are actually stored within directories under TIF. You could modify your original code as below to achive your desired result.
My.Application.DoEvents()
        Dim DSPath As String = "C:\Documents and settings\username\local settings\temporary internet files"
        'Dim DSPath As String = "C:\Documents and Settings\" & GetUsername(My.User.Name) & "\Local Settings\Temporary Internet Files"
        Dim DS As New System.IO.DirectoryInfo(DSPath)
        Dim DFI() As New System.IO.FileInfo = DS.GetFiles("*.*", SearchOption.AllDirectories)
        Dim FI As System.IO.FileInfo

        Console.WriteLine(FIA.Length)
        For Each FI In DFI
            Me.TBStatus.Text = "Cleaning Cookies: " & FI.FullName
            Console.WriteLine(FI.FullName)
        Next

Open in new window

0
 
zadeveloperCommented:
try this:
Dim dir As String = "C:\Documents and settings\username\local settings\temporary internet files\"
        If Directory.Exists(dir) Then
            Directory.Delete(dir & "*.*", True)
        End If

Open in new window

0
 
beaconlightboyAuthor Commented:
Ok but i don't want to delete the directory, and that doesn't explain why the code doesn't show the directory listing when i select that directory as opposed to others.
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
zadeveloperCommented:
The code will not delete the root directory. Use directory.getfiles(path) to show the contents, the way u are doing it filters out hidden objects
0
 
beaconlightboyAuthor Commented:
huh, nice of them to tell you that in the documentation.  i will try it.
0
 
zadeveloperCommented:
Cool
0
 
zadeveloperCommented:
Cool
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.