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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

filename in a variable

Status
Not open for further replies.

Matta25

Technical User
Jan 6, 2004
82
0
0
US
Hello all,
I'm very new to VB in general. I'm using VB.net.
I have many *.txt files I need to open and read a line.
How can I tell VB.net to find the *.txt files in a c:\test folder and place the whole name (and or Path) in to a varaiable.
Thanks
 
Have a look at the System.IO.Directory.GetFiles method


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
I looked at it and i'm still stuck. Any sample code to do this. thanks
 
Following ca8msm's advice and using Intellisense coupled with the property grid set to show dynamic help, I managed to put this together:

Code:
  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Dim path As String = "C:\Windows\Internet Logs\"
    Dim di As New System.IO.DirectoryInfo(path)
    Dim fi() As System.IO.FileInfo = di.GetFiles("*.txt")
    For a As Integer = 0 To fi.Length - 1
      ListBox1.Items.Add(fi(a).Name)
    Next

  End Sub

Hope this helps.

[vampire][bat]
 
Sorry, I forgot to mention that that does not give you exactly what you want - but it is very close.


Hope this helps.

[vampire][bat]
 
Thanks for the sample earthandfire. Thank did it.
Thanks again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top