Parsing folders in path using FolderBrowserDialog

G

Guest

I thought this would be a simple one but I can't quite figure it out.

I'm using the FolderBrowserDialog to select a path for file saving. Every
time the user changes the path, I want to grab the very last folder in that
path because it's used to generate automatic default file names. I'm trying
to find a built-in method for doing this but haven't found one. I thought
I'd find the answer in System.IO but can't quite seem to. I need something
analogous to GetRootFolder only I just need the last folder in the chain.

Anyway ideas? Thanks in advance.
 
A

Atul

Search for the first Path.DirectorySeparatorChar value from the end of the
folder string. The selected folder name is the substring from that position
to the end.

You might also want to take a look at FolderView Control at
http://www.ssware.com/fldrview.htm which provides easy access to such
information.

-Atul
http://www.ssware.com/
Shell MegaPack - Windows Explorer Shell Controls for ActiveX and .Net
 
G

Guest

Yeah, I knew how to hash it out, but thought there'd be a more elegant
solution.

Here's some code that wound up working:

Dim folderPrefix As String
Dim tempDirectory As System.IO.DirectoryInfo = New
System.IO.DirectoryInfo(FolderBrowserDialog1.SelectedPath)
If tempDirectory.GetDirectories().Length > 0 Then
WorkbookName_text.Text = folderPrefix & " " &
Trim(Str(Math.Abs(tempDirectory.GetFiles("*.xls").Length + 1)))
Else
WorkbookName_text.Text = String.Empty
End If

Thanks though!

Randall
 
T

Tom Shelton

I thought this would be a simple one but I can't quite figure it out.

I'm using the FolderBrowserDialog to select a path for file saving. Every
time the user changes the path, I want to grab the very last folder in that
path because it's used to generate automatic default file names. I'm trying
to find a built-in method for doing this but haven't found one. I thought
I'd find the answer in System.IO but can't quite seem to. I need something
analogous to GetRootFolder only I just need the last folder in the chain.

Anyway ideas? Thanks in advance.

Dim di As New DirectoryInfo (PATH)
Console.WriteLine (di.Name)

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top