hog Posted July 20, 2005 Posted July 20, 2005 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 Quote My website
Afraits Posted July 20, 2005 Posted July 20, 2005 Directory class GetDirectories method returns a string array of the subdirectories. e.g. Dim subdirectoryEntries As String() = Directory.GetDirectories(targetDirectory) Quote Afraits "The avalanche has started, it is too late for the pebbles to vote"
hog Posted July 20, 2005 Author Posted July 20, 2005 Cheers ears! I am trying to avoid none .NET functions! Quote My website
hog Posted July 20, 2005 Author Posted July 20, 2005 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 Quote My website
hog Posted July 20, 2005 Author Posted July 20, 2005 I have just seen my error :p I am obtaining the entire length of the string.....plonker! Quote My website
hog Posted July 20, 2005 Author Posted July 20, 2005 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 Quote My website
Diesel Posted July 20, 2005 Posted July 20, 2005 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] Quote
Leaders Iceplug Posted July 24, 2005 Leaders Posted July 24, 2005 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.) Quote Iceplug, USN One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.