6 Replies - 4588 Views - Last Post: 10 February 2008 - 03:44 PM Rate Topic: -----

#1 theholygod  Icon User is offline

  • D.I.C Regular

Reputation: 7
  • View blog
  • Posts: 342
  • Joined: 05-February 06

Listing files in a text box (Visual Basic 2005)

Post icon  Posted 10 February 2008 - 12:59 PM

Im not sure where to start with this really, but using a modified example off the internet i have written the following:

		' make a reference to a directory
		Dim di As New IO.DirectoryInfo("D:\maps\")
		Dim diar1 As IO.FileInfo() = di.GetFiles()
		Dim dra As IO.FileInfo
		Dim a As Integer

		'list the names of all files in the specified directory
		For Each dra In diar1
			For a = 0 To dra.Length
				If dra.Extension.ToString = "bsp" Then
					txtOutput.Text = dra.Name.IndexOf(a) & vbCrLf
				End If
			Next
		Next


This is on a button event. What i would like it to do is go through a directory looking for files with the extension ".bsp" and adding those files on a new line in a multiline text box. Is this code anywhere near what i am aiming to do?

Is This A Good Question/Topic? 0
  • +

Replies To: Listing files in a text box (Visual Basic 2005)

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1638
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Listing files in a text box (Visual Basic 2005)

Posted 10 February 2008 - 01:04 PM

Move to VB.Net :)
Was This Post Helpful? 0
  • +
  • -

#3 theholygod  Icon User is offline

  • D.I.C Regular

Reputation: 7
  • View blog
  • Posts: 342
  • Joined: 05-February 06

Re: Listing files in a text box (Visual Basic 2005)

Posted 10 February 2008 - 01:49 PM

why? im using visual basic 2005, not .net
Was This Post Helpful? 0
  • +
  • -

#4 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Listing files in a text box (Visual Basic 2005)

Posted 10 February 2008 - 02:20 PM

Visual Basic 2005 is in the .NET framework. So this is the correct forum for posts related to VB.NET.
Was This Post Helpful? 0
  • +
  • -

#5 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1638
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Listing files in a text box (Visual Basic 2005)

Posted 10 February 2008 - 03:06 PM

You are definitely on the right path, though just for personal preference I would use a For Each loop as it will require a single loop, thus involving less code, like so:


' make a reference to a directory
		Dim di As New IO.DirectoryInfo("D:\maps\")
		For Each file As IO.FileInfo in di.GetFiles()
			If file.Extension = "bsp" Then
				 txtOutput.Text += file.Name & vbCrLf
			End If
		Next




The way you had your code you would have overwritten what was in your TextBox on each iteration of your loop, changing it to =+ adds a new line on each iteration.

Hope that helps :)
Was This Post Helpful? 0
  • +
  • -

#6 theholygod  Icon User is offline

  • D.I.C Regular

Reputation: 7
  • View blog
  • Posts: 342
  • Joined: 05-February 06

Re: Listing files in a text box (Visual Basic 2005)

Posted 10 February 2008 - 03:31 PM

Agh, i cant believe i overlooked that.

Woo! i just changed "bsp" to ".bsp" and it worked exactly as i wanted. Thanks so much!
Was This Post Helpful? 0
  • +
  • -

#7 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1638
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Listing files in a text box (Visual Basic 2005)

Posted 10 February 2008 - 03:44 PM

No problem, glad I could help. Also, sorry for the confusion between VB and VB 2005. Next time Ill explain when I move a post :)

Now tell all your friends about us here at DIC :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1