enumerate files

  • Thread starter Thread starter Doug Versch
  • Start date Start date
D

Doug Versch

Hi,
I wanted to list all files in a directory so I found some code:
Dim t(), st As String

t = System.IO.Directory.GetFiles(System.IO.Directory.GetCurrentDirectory,
"*.txt")

Dim en As System.Collections.IEnumerator

en = t.GetEnumerator

While en.MoveNext

st = CStr(en.Current)

ComBoFilel.Items.Add(st)

End While

To add just the name of the file rather than its whole path, do I need to do
some string manipulation to find the last "\" or is there a simpler method

Thanks

DV
 
To add just the name of the file rather than its whole path, do I need to do
some string manipulation to find the last "\" or is there a simpler method

System.IO.Path.GetFileName()



Mattias
 
I solved this using:

Dim st As String

Dim di As DirectoryInfo = New DirectoryInfo(Directory.GetCurrentDirectory)

st = di.FullName

Dim fis As FileInfo() = di.GetFiles("*.txt")

Dim fil As FileInfo

For Each fil In fis

st = fil.Name.ToString

ComBoPalleteLbl.Items.Add(st)

Next fil
 
Back
Top