Read Filenames from C:\Folder

R

rbutch

guys, i need a little help with this.
this is working (well sort of)
i get the info, but it's not moving to a new line as it iterates thru the array
and all of the fields are like ONE HUGE LONG string
'declare an array

Dim filenames() As String
filenames = Directory.GetFiles("C:\Re_Class")
Dim i, o As Integer
Dim info As String

For i = 0 To filenames.Length - 1
'i do a substring to do away with the pathname

info += (filenames(i).Substring(12)) & ControlChars.CrLf
Next i

lstOne.Items.Add(info.ToString)

im then adding it to a list box. if i use a dropdown box the results are the same
this is a web app (asp.net/w/vb.net), just pulling file names from the root directory.
so, im getting info, i just need to have it start a new line on each iteration
thanks again
rik

**********************************************************************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
 
M

Matt Berther

Hello rik,

Why not something like this:

Dim filenames() As String = Directory.GetFiles("C:\Re_Class")
Dim i, o As Integer
Dim filename As String

For i = 0 To filenames.Length - 1
filename = Path.GetFileName(filenames(i)) ' This is much better than
relying on substring to be accurate
lstOne.Items.Add(filename)
Next i

The problem with your code is that you are adding one string, rather than
individual strings. Each item in a list is one object.
 
R

rbutch

absolutely awesome Matt.
works like a charm
thank you again
rik

**********************************************************************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
 

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

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,740
Latest member
JudsonFrie

Latest Threads

Top