Connecting Tech Pros Worldwide Help | Site Map

how to list out all the folder names in the directory

Newbie
 
Join Date: Mar 2007
Posts: 29
#1: May 18 '07
hi, i'm helping my friend ask..is there a way to list out all the name of the folder in a directory eg. C:\. Thanks.

p.s using vb 2005
shidec's Avatar
Newbie
 
Join Date: May 2007
Posts: 27
#2: May 18 '07

re: how to list out all the folder names in the directory


use System.IO to process anyting about file & folder

Expand|Select|Wrap|Line Numbers
  1.  
  2.         Dim files() As String
  3.         Dim i As Integer
  4.         files = System.IO.Directory.GetFiles(System.IO.Directory.GetCurrentDirectory)
  5.         For i = 0 To files.Length - 1
  6.             TextBox1.Text = TextBox1.Text + files(i) + vbCrLf
  7.         Next
  8.  
Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,150
#3: May 18 '07

re: how to list out all the folder names in the directory


Take a look at Directory.GetDirectories()
Expand|Select|Wrap|Line Numbers
  1. string[] directorynames=Directory.GetDirectories(path, searchpatttern, searchoptions);
  2.  
(NOTE: You will have to make that VB code and not C#, but the calls are the same)
Reply