Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I have just created some code, mainly from the help, which gets all the directory names within a given directory.

 

This code uses the DIR function, which I think is the visual basic function not .NET?

 

Is there a better function to use?

 

Thnx

My website
Posted

Directory class GetDirectories method returns a string array of the subdirectories.

e.g.

Dim subdirectoryEntries As String() = Directory.GetDirectories(targetDirectory)

Afraits

"The avalanche has started, it is too late for the pebbles to vote"

Posted

So where am I going wrong here? I am trying to obtain only the subdirectory name rather than the full path. All I get is blanks?

 

Dim strDirectories As String() = Directory.GetDirectories(Application.StartupPath & "\photos\")

       Dim intCharCount, intIndex As Integer

       Dim strDirectory As String

       intIndex = 0

       For Each strDirectory In strDirectories

           intCharCount = strDirectories(intIndex).Length

           Me.cboSites.Items.Add(strDirectory.Substring(intCharCount))

           intIndex += 1

       Next

My website
Posted

Dim strPath As String = Application.StartupPath & "\photos\"

       Dim strDirectories As String() = Directory.GetDirectories(strPath)

       Dim intCharCount As Integer

       Dim strDirectory As String

       For Each strDirectory In strDirectories

           intCharCount = strPath.Length

           Me.cboSites.Items.Add(strDirectory.Substring(intCharCount))

       Next

 

:D

My website
Posted

Sorry, I hate unneccessary locals

 


Dim strPath As String = Application.StartupPath & "\photos\"

For Each strDirectory As String In System.IO.Directory.GetDirectories(strPath)
Me.cboSites.Items.Add(strDirectory.Substring(intCharCount))
Next
[/Code]

  • Leaders
Posted
Though your example isn't too bad, it is good practice to keep your lines simple, so it is easier to decipher what your procedures are doing. :) (Also, if I'm not mistaken, you can't put As String in the For Each Loop on .NET 2002.)

Iceplug, USN

One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...