Thanks Ken, Had a look, copied and pasted the code example and altered it as below but I still don't see how to get the names of the folders when it's run I just get the number 11 in the listbox, I guess that's because I have .Length but I can not see .Name anywhere and if I leave it off and run the program I get FileInfo[]Array in the listbox. I've decided that the MS Helpfiles are not that Helpful, if they were we would not have all these .Net forums on the web to Help us understand .Net, Ok moan over.
Dim di As DirectoryInfo = New DirectoryInfo("C:\MyFolder\")
Dim dirs As DirectoryInfo() = di.GetDirectories() Dim diNext As DirectoryInfo
For Each diNext In dirs lstFolders.Items.Add(diNext.GetFiles().Length) Next
Thanks again Ahmedilyas, The second worked Me.lstTheme.Items.Add(currentFolder.Substring(currentFolder.LastIndexOf("\") + 1))
The first one did not Me.lstTheme.Items.Add(currentFolder.Remove("\\", "")) Gave this error message Conversion from string "\\" to type 'Integer' is not valid.
Thanks for the reply this is as close as I've been to what I want, Here's what I'm getting now, how do I remove the backslash \ \Folder1 \Folder2 \Folder3
woops! having bad days here, it should be Replace, not remove (silly me!) my apologese - again, its better to use the REPLACE method than the second approach
List Folderames in a folder
Darathar
Justin Tang
you can either do a remove:
currentFolder.Remove("\\", "")
or
Me.theListBox.Items.Add(currentFolder.SubString(currentFolder.LastIndexOf("\") + 1))
safer would be the first one :)
Eng. Habeeli
Aurrin
Had a look, copied and pasted the code example and altered it as below but I still don't see how to get the names of the folders when it's run I just get the number 11 in the listbox, I guess that's because I have .Length but I can not see .Name anywhere and if I leave it off and run the program I get FileInfo[]Array in the listbox.
I've decided that the MS Helpfiles are not that Helpful, if they were we would not have all these .Net forums on the web to Help us understand .Net, Ok moan over.
Dim di As DirectoryInfo = New DirectoryInfo("C:\MyFolder\")
Dim dirs As DirectoryInfo() = di.GetDirectories()
Dim diNext As DirectoryInfo
For Each diNext In dirs
lstFolders.Items.Add(diNext.GetFiles().Length)
Next
mqsash
The second worked
Me.lstTheme.Items.Add(currentFolder.Substring(currentFolder.LastIndexOf("\") + 1))
The first one did not
Me.lstTheme.Items.Add(currentFolder.Remove("\\", ""))
Gave this error message
Conversion from string "\\" to type 'Integer' is not valid.
Rafael Leonhardt
Like that, one liner, problem is that in the listbox I'm showing
C:\MYFOLDER\Folder1
C:\MYFOLDER\Folder2
C:\MYFOLDER\Folder3
What I want to show is just the folder name not the full path
Folder1
Folder2
Folder3
Ramanujam Sampath
You can simplify this to a single line
Me.ListBox1.DataSource = My.Computer.FileSystem.GetDirectories("C:\MYFOLDER\")Hila123
Here's what I'm getting now, how do I remove the backslash \
\Folder1
\Folder2
\Folder3
windoze
Scott Anthony
Me.lstTheme.Items.Add(currentFolder.Replace("C:\MYFOLDERS\", ""))
Cheers
Ahmedilyas
N3UD
Kevin8264
you would pretty much do a string parsing process:
Dim theFolders() as String
theFolders = Directory.GetDirectories(path)
for each currentFolder as string in theFolders
Me.theListBox.Items.Add(currentFolder.SubString(currentFolder.LastIndexOf("\"))
next
that should do it hopefully.
Another way would be:
Path.GetDirectoryName(currentFolder)
in the for each loop
does this help