List all folders in a directory

Im looking for a program that would be able to list all the folders in Documents and Settings, so I can get a list of users that can log onto a pc.
Who is Participating?
this also works for non-english systems (tested on english, german and french systems) where it may be called 'Dokuments' or some such spelling.

        For Each dir As String In System.IO.Directory.GetDirectories(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\..\..\")
Carl TawnSystems and Integration DeveloperCommented:
You can use the following to enumerate the directories:

        Dim dir As DirectoryInfo = New DirectoryInfo("C:\Documents and settings")
        For Each d As DirectoryInfo In dir.GetDirectories()
            MessageBox.Show(d.FullName)         '// Full path + Name
            MessageBox.Show(d.Name)             '// Name only
Fahad MukhtarDistinguished EngineerCommented:
Use the following code to automatically get the SystemDrive and then list all the users in the system

For Each user As String In System.IO.Directory.GetDirectories(Environment.GetEnvironmentVariable("SystemDrive") + "\Documents and Settings")
Wayne Taylor (webtubbs)Commented:
You can also get a list of users on a computer using the following code....

Imports System.Management

Public Class Form1
    Inherits System.Windows.Forms.Form

    '....Form Design Code....

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim Domain As String = System.Windows.Forms.SystemInformation.ComputerName 'Gets the current computer's name
        Dim msg As String

        Dim UserQuery As String = "SELECT * FROM Win32_UserAccount WHERE Domain='" & Domain & "'"
        Dim Query As New ManagementObjectSearcher(UserQuery)

        Dim User As ManagementObject
        For Each User In Query.Get()
            msg &= "User name: " & User("Name").ToString() & vbNewLine

        MessageBox.Show(msg, "List of Users", MessageBoxButtons.OK)

    End Sub
End Class

You'll need to add a reference to System.Management.


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.