Read Filenames from C:\Folder

Discussion in 'ASP .Net' started by rbutch@coair.com, Jan 21, 2005.

  1. Guest

    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...
     
    , Jan 21, 2005
    #1
    1. Advertising

  2. Matt Berther Guest

    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.

    --
    Matt Berther
    http://www.mattberther.com

    > 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...
     
    Matt Berther, Jan 21, 2005
    #2
    1. Advertising

  3. Guest

    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...
     
    , Jan 21, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Edison Carter
    Replies:
    1
    Views:
    456
    brucie
    Sep 30, 2003
  2. B.J.
    Replies:
    4
    Views:
    746
    Toby Inkster
    Apr 23, 2005
  3. fscked
    Replies:
    3
    Views:
    266
    fscked
    May 1, 2007
  4. Steve Karnath

    Reading filenames in a folder

    Steve Karnath, Sep 18, 2003, in forum: ASP General
    Replies:
    6
    Views:
    165
    Ray at
    Sep 18, 2003
  5. Replies:
    5
    Views:
    161
    Dr.Ruud
    Jun 7, 2006
Loading...

Share This Page