Results 1 to 2 of 2

Thread: How do I remove the directory structure in file name in this function?

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2007
    Posts
    63

    Question How do I remove the directory structure in file name in this function?

    Hello,

    I am listing files in a certain directory into a list box using the following code I found on this Forum (Thanks mpdeglau).

    lstFiles.Items.AddRange(System.IO.Directory.GetFiles("C:\Test Files\Data Entry Process\", "*.XLS", IO.SearchOption.TopDirectoryOnly))

    The file names are then listsed in the the list box but the problem is that it also includes the direcotry path also. like this.

    C:\Test Files\Data Entry Process\test.xls

    How do I have it not include the directory structure? so it would then just show

    test.xls

    Is there an option to do this?

    Thanks for your help

    Mythos
    Last edited by Mythos44; Nov 2nd, 2007 at 03:03 PM. Reason: a little clearer title

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: How do I remove the directory structure in file name in this function?

    You have to manually remove it from each file path (using System.IO.Path class) then add the file name to your list.
    Code:
    Dim theFiles() As String = System.IO.Directory.GetFiles("C:\Test Files\Data Entry Process\", "*.XLS", IO.SearchOption.TopDirectoryOnly)
    For Each file As String In theFiles
        lstFiles.Items.Add(System.IO.Path.GetFileName(file))
    Next

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width