• 0

[VB.NET] Listing directory contents


Question

I need a list of all cookie files for the currently logged in user so here is my code:

'inside the form's load event
        Dim strFiles() As String
        Dim strFile As String
        strFiles = System.IO.Directory.GetFiles(CookieDir)
        For Each strFile In strFiles
            MsgBox(strFile) 'just using msgbox as an example
        Next
'

    Private Function CookieDir() As String
        Dim regCookieDir As Microsoft.Win32.RegistryKey
        regCookieDir = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE").OpenSubKey("Microsoft").OpenSubKey("Windows").OpenSubKey("CurrentVersion").OpenSubKey("Internet Settings").OpenSubKey("Cache").OpenSubKey("Special Paths").OpenSubKey("Cookies")
        CookieDir = regCookieDir.GetValue("Directory")
    End Function

But only 10 files are listed/shown... I can look in my cookies directory in explorer (the same one being returned by CookieDir()) and see 214 objects.. why doesn't the array contain all the files?

Link to comment
Share on other sites

7 answers to this question

Recommended Posts

  • 0

I don't know. I see all of mine when I do this.

BTW, you don't need to use OpenSubKey for each key. Just specify the whole string as a subkey.

Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\Cache\Special Paths\Cookies")

Link to comment
Share on other sites

  • 0

Thanks for the tip, but meh.. this is odd.. I don't see all of the files

Edit: Figured it out.. I am developing in VMware temporarily and that Windows installation doesn't have many cookies.. when I was looking in my cookies directory in explorer, it was on my real machine, not VMware. :/

Problem solved :)

Link to comment
Share on other sites

  • 0

Thanks, but this software is specific to IE :p

Small question.. I've noticed there's no "Continue" for For Each loops in vb.net .. am I stuck with If statements that indent my source half way to China? (not really, it's only one, but "Continue" would be cleaner than negating the if and including everything inside)

For example, I want to skip over index.dat and it would be much cleaner to do

If (whatever = "index.dat") Then Continue
'a bunch of code

than

If (whatever <> "index.dat") Then
'a bunch of code
End If

Link to comment
Share on other sites

  • 0

Instead of

strFiles = System.IO.Directory.GetFiles(CookieDir)

it should be better to use

strFiles = System.IO.Directory.GetFiles(CookieDir, "*.txt")

so that you only gets cookie files. You won't need the additional if condition.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.