By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,761 Members | 959 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,761 IT Pros & Developers. It's quick & easy.

Parsing folders in path using FolderBrowserDialog

P: n/a
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.
Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies

P: n/a
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
"Randall Arnold" <Ra***********@discussions.microsoft.com> wrote in message
news:D9**********************************@microsof t.com...
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.

Nov 21 '05 #2

P: n/a
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.Selec tedPath)
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

"Atul" wrote:
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
"Randall Arnold" <Ra***********@discussions.microsoft.com> wrote in message
news:D9**********************************@microsof t.com...
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.


Nov 21 '05 #3

P: n/a
In article <D9**********************************@microsoft.co m>, Randall Arnold wrote:
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
--
Tom Shelton [MVP]
Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.