473,396 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Parsing folders in path using FolderBrowserDialog

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
3 4191
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Michael Howes | last post by:
I'm working in C#/.Net Desktop shortcuts to folders are now shown in the FolderBrowserDialog. Is there any way to have them show up? thanks mike
3
by: Neil Ginsberg | last post by:
I need to write some code that will get all filenames under a particular directory and add them to a table, including any in subdirectories. I realize that Dir can be used to get all filenames in a...
3
by: MAF | last post by:
Does anyone know how to set a specific path for the FolderBrowser object? here is my existing code. private FolderBrowserDialog m_fb = new FolderBrowserDialog(); private DialogResult...
3
by: Gustaf | last post by:
Using VS.NET 2003 with all the 1.1 framework updates. I've been subjected to this bug in 2 separate projects, and in both cases, I've found no way back other than starting from scratch again (which...
0
bplacker
by: bplacker | last post by:
I am trying to use the FolderBrowserDialog to select a folder... and from there, programatically find each folder, go into that folder, and pull out all filenames within the folder. Does that make...
1
by: Riky | last post by:
hi i have a windows application. I am select the folder or file name from the folderbrowserdialog box and to delete the folder or file i am calling the following code. Public Function...
1
by: sunny74 | last post by:
I am writing a ASP.NET 2.0 web based application in which I want the user to create & select a Folder using Windows Explorer.After the user creates and selects the folder, on pressing OK I should be...
0
by: TG | last post by:
hi! I am working with VB 2008. I want to be able to run this program say in N:\ and it will show me in an excel sheet the following: Folder Path Size(GB) Count of Files N:\Clients 0.53 308 ...
0
by: Ronnie1987 | last post by:
Hi, I am currently using FolderBrowserDialog class to access folders across the network. My problem is that when i click a folder, the Windows Authentication dialog does not appear and sub-folders...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.