9 Replies - 14403 Views - Last Post: 20 November 2009 - 10:18 AM Rate Topic: -----

#1 EndLessMind  Icon User is offline

  • Android Expert
  • member icon

Reputation: 271
  • View blog
  • Posts: 1,250
  • Joined: 13-March 09

Count directories in folder? how do i?

Posted 19 November 2009 - 02:22 PM

Hi!
I need to count the numers of directories in a folder( by path )
How can i do that?
should i just add something to this?:
		Dim path As String = Application.StartupPath & "\Bin\"
		Dim sf As String
		For Each sf In Directory.GetDirectories(path)
Next


Thanks in advance

This post has been edited by EndLessMind: 19 November 2009 - 02:22 PM

Is This A Good Question/Topic? 0
  • +

Replies To: Count directories in folder? how do i?

#2 crepitus  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 85
  • View blog
  • Posts: 383
  • Joined: 08-September 09

Re: Count directories in folder? how do i?

Posted 19 November 2009 - 02:27 PM

GetDirectories returns an array, so just use the length of that array.

This will only get the count of the immediate subdirectories.
Was This Post Helpful? 0
  • +
  • -

#3 EndLessMind  Icon User is offline

  • Android Expert
  • member icon

Reputation: 271
  • View blog
  • Posts: 1,250
  • Joined: 13-March 09

Re: Count directories in folder? how do i?

Posted 19 November 2009 - 02:29 PM

View Postcrepitus, on 19 Nov, 2009 - 01:27 PM, said:

GetDirectories returns an array, so just use the length of that array.

This will only get the count of the immediate subdirectories.

could you please post a example? :)
Was This Post Helpful? 0
  • +
  • -

#4 mihaispr  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 114
  • Joined: 29-September 09

Re: Count directories in folder? how do i?

Posted 20 November 2009 - 05:49 AM

Hi !

Hope that this can help you:

Dim counter As _
System.Collections.ObjectModel.ReadOnlyCollection(Of String)
counter = My.Computer.FileSystem.GetFiles("C:\YourTestDirectory")
MsgBox("number of files is " & CStr(counter.Count))



I have found a reference through the microsoft site:

http://msdn.microsof...28VS.80%29.aspx


Maybe this is useful for you!

Mike
Was This Post Helpful? 0
  • +
  • -

#5 mihaispr  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 114
  • Joined: 29-September 09

Re: Count directories in folder? how do i?

Posted 20 November 2009 - 05:55 AM

You can count this in a label:

Label1.Text = CInt(counter.Count)

This post has been edited by mihaispr: 20 November 2009 - 05:55 AM

Was This Post Helpful? 0
  • +
  • -

#6 Aurel300  Icon User is offline

  • D.I.C Head

Reputation: 13
  • View blog
  • Posts: 230
  • Joined: 10-November 07

Re: Count directories in folder? how do i?

Posted 20 November 2009 - 06:28 AM

Neither CInt nor ToString functions arenīt really needed - VB.Net automatically converts numbers to strings when you assign them to a string.

This post has been edited by Aurel300: 20 November 2009 - 06:29 AM

Was This Post Helpful? 0
  • +
  • -

#7 EndLessMind  Icon User is offline

  • Android Expert
  • member icon

Reputation: 271
  • View blog
  • Posts: 1,250
  • Joined: 13-March 09

Re: Count directories in folder? how do i?

Posted 20 November 2009 - 08:54 AM

Sure. but i know how to count files. but i want to count folders.

This post has been edited by EndLessMind: 20 November 2009 - 09:20 AM

Was This Post Helpful? 0
  • +
  • -

#8 crepitus  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 85
  • View blog
  • Posts: 383
  • Joined: 08-September 09

Re: Count directories in folder? how do i?

Posted 20 November 2009 - 09:20 AM

View PostEndLessMind, on 19 Nov, 2009 - 01:29 PM, said:

could you please post a example? :)


Dim count As Integer = IO.Directory.GetDirectories("C:\").Length
Was This Post Helpful? 0
  • +
  • -

#9 EndLessMind  Icon User is offline

  • Android Expert
  • member icon

Reputation: 271
  • View blog
  • Posts: 1,250
  • Joined: 13-March 09

Re: Count directories in folder? how do i?

Posted 20 November 2009 - 09:38 AM

View Postcrepitus, on 20 Nov, 2009 - 08:20 AM, said:

View PostEndLessMind, on 19 Nov, 2009 - 01:29 PM, said:

could you please post a example? :)


Dim count As Integer = IO.Directory.GetDirectories("C:\").Length

Thanks. But now i got a new problem. i have a downloaded a "imagecombobox"
and i cant just "imagecombobox1.items.add(count)" om something.
if a want to add a text to a imagecombobox item i have to do like this
ImageComboBoxEdit1.Properties.Items(1).Description = "Hello"

do add a items i have to
ImageComboBoxEdit1.Properties.Items.Add(whatever)
but then i just adds a item with no text. so i dont know how to add a item for each folder in the path. and then add the names. ( and maybe the icon to.. but i can use a imagelist for that )

i can post a link to the site where i downloaded it from. itīs just a trail version but if you count try to solve it.. that i would be happy :)
Here it the link: http://devexpress.co...HMHelp.v9.2.zip
Was This Post Helpful? 0
  • +
  • -

#10 EndLessMind  Icon User is offline

  • Android Expert
  • member icon

Reputation: 271
  • View blog
  • Posts: 1,250
  • Joined: 13-March 09

Re: Count directories in folder? how do i?

Posted 20 November 2009 - 10:18 AM

iīve been working on this code:
		Dim imgcbbox As New DevExpress.XtraEditors.ImageComboBoxEdit
		Dim s As String
		Dim i As Integer = imgcbbox.Properties.Items.Count
		For Each s In Directory.GetDirectories(path)
			imgcbbox.Properties.Items.Add(s)
			i = i + 1
			imgcbbox.Properties.Items(i).Description = s
		Next

i hope i dont have to explane what it does, becuase my english isīnt so good ^^

but i get error saying that value is out of rage of out of index som something like that.. =/
i want to add a new imagecombobox.item and get the count of it to "i"
and then add the "s" in to a "i".. hope you understand ^^

This post has been edited by EndLessMind: 20 November 2009 - 10:23 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1