eyeball Posted September 24, 2007 Posted September 24, 2007 (edited) Hi all,i recently started building a project i have wanted to do for a long time, i dived into Vb .NET 2005 and im loving it, but i need some help if anyone has any experience with it.im trying to specify a directory (which i can do) and then have it look at each sub directory in turn and return the name of that directoryeg.m:\testshould return "test"files have a .fullname property, but im not sure if directories do?i think i need a for each loop, but im not sure.if i can just make it pop each subdirectories name up a in a msgbox for now that would be great, then il move onto to doing more with it.thanks Edited September 24, 2007 by eyeball
jcarle Posted September 24, 2007 Posted September 24, 2007 You need a recursive function.First, add an Imports System.IO statement.Then create the following function:Private Function Recursive(ByVal strPath As String) Dim oDir As New DirectoryInfo(strPath) Dim oSubDir() As DirectoryInfo Dim i As Int32 oSubDir = oDir.GetDirectories() For i = 0 To oSubDir.Length - 1 'Do something with the directory, in this case spit it out to the Debug Output window. Debug.WriteLine(oSubDir(i).Name.ToString) Call Recursive(oSubDir(i)) Next End FunctionStart it by calling recursive the first time on the root folder to begin at... Call Recursive("C:\Folder\")
eyeball Posted September 24, 2007 Author Posted September 24, 2007 thanks jcarle i got this code which also works For Each folder As String In IO.Directory.GetDirectories(txtDirectory.Text) MessageBox.Show(IO.Path.GetFileName(folder)) Next folderwhich one is better in your opinion? and why? thank you
jcarle Posted September 24, 2007 Posted September 24, 2007 thanks jcarle i got this code which also works For Each folder As String In IO.Directory.GetDirectories(txtDirectory.Text) MessageBox.Show(IO.Path.GetFileName(folder)) Next folderwhich one is better in your opinion? and why? thank you That'll do the folders in a folder, but it won't do the subfolders of those folders...
eyeball Posted September 25, 2007 Author Posted September 25, 2007 ah i see,i only wanted to do one level of folders, but thanks for the help though, much appreciated
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now