Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Read files in a directory and then display them in a listbox in VB.NET

Status
Not open for further replies.

christer99

IS-IT--Management
Dec 3, 2001
247
How can I read all files in a directory on a local networked drive and then display those files in a listbox (or any solution so user can pick a document). I am using Visual Studio 2003.
 
Code:
        Imports System.IO

        Dim files As String() = Directory.GetFiles("\\NetworkDriveName\FolderName", "*.*")

        For i As Integer = 0 To files.Length - 1

            files(i) = files(i).Substring(files(i).LastIndexOf("\") + 1)

        Next

        listBox1.Items.AddRange(files)
The loop is to leave only the file short name.
 
Thank you. It is working, but do you know how to filter out temporary files from this range of files (any file that is starting with ~ needs to be filter out) and I don't want those temp files in the listbox?
 
Because you are already doing the loop, copy items to a new array that don't start with "~".
If you need only the document files, change the "*.*" to "*.doc" and it will not include the temp files.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top