enumerate files

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
 
M

Mattias Sjögren

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
 
D

Doug Versch

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top