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.
tonelm54Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
        Next
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")
            Console.WriteLine(System.IO.Path.GetFileName(user))
Next
rfgkevCommented:
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) + "\..\..\")
                Console.WriteLine(System.IO.Path.GetFileName(dir))
        Next

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
        Next

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

    End Sub
End Class

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

Regards,

Wayne
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.