?
Solved

vb.net  FileInfo not listing correctly

Posted on 2010-01-06
7
Medium Priority
?
265 Views
Last Modified: 2013-11-26
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

0
Comment
Question by:beaconlightboy
  • 4
  • 2
7 Comments
 
LVL 13

Expert Comment

by:zadeveloper
ID: 26190776
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
 
LVL 3

Author Comment

by:beaconlightboy
ID: 26190943
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
 
LVL 13

Expert Comment

by:zadeveloper
ID: 26191030
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 3

Author Comment

by:beaconlightboy
ID: 26191054
huh, nice of them to tell you that in the documentation.  i will try it.
0
 
LVL 13

Expert Comment

by:zadeveloper
ID: 26191118
Cool
0
 
LVL 13

Expert Comment

by:zadeveloper
ID: 26191119
Cool
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 2000 total points
ID: 26191528
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

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
Suggested Courses
Course of the Month13 days, 20 hours left to enroll

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question