List all folders in a directory

Posted on 2006-04-27
Last Modified: 2010-04-23
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.
Question by:tonelm54
    LVL 52

    Expert Comment

    by:Carl Tawn
    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
    LVL 19

    Expert Comment

    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")
    LVL 8

    Accepted Solution

    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) + "\..\..\")
    LVL 46

    Expert Comment

    by:Wayne Taylor (webtubbs)
    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.



    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    794 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

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now