views:

50

answers:

3

I'm using Managed C++.
I need to extract the parent directory after OpenFileDialog returns the String^ file path.

System::String^ filestring = openFileDialog1->FileName;  

The method that microsoft uses is Directory::GetParent but this must be saved as

System::IO::DirectoryInfo^ WhyIsThisNotAString = Directory::GetParent(filestring)  

I need to somehow convert from DirectoryInfo^ to String^.

I have also tried this after OpenFileDialog is called, but it does not work:

String^ CurrDir = Directory::GetCurrentDirectory();  

Or if there is a better way to extract the parent directory that would be great.
Thanks

+2  A: 

You can use the FullName property:

System::String^ directoryFullName=Directory::GetParent(filestring)->FullName;
Michael Goldshteyn
+2  A: 

Have you looked at the documentation?

The DirectoryInfo class has a FullName property with the following description:

Gets the full path of the directory or file.

André Caron
`+1`, for sometimes RTFM is all you can answer.
sbi
I have been RTFM, for about 20 minutes, but searching through msdn references can be a bit time consuming. The point of this website is to HELP people who are not as knowledgeable. Not be a condescending prick.
Nick S.
Actually, MSDN is a *reference*: it is designed to help you when you *already know where* to find what you're looking for. If you don't feel you are knowledgeable enough, you should go out and buy a book on .NET that has a broader view and points to different classes. Those two and Google are three complementary views of the same information.
André Caron
+1 for RTFM. In the old days MIT organized the Usenet forum FAQs, plus other docs, in a nice collection called RTFM (Read The Fucking Manual). The site is still [there](ftp://rtfm.mit.edu/)... However, recent MIT [courseware](http://tinyurl.com/mit-cpp-course-errors) shows that they have now, themselves, forgotten to RTFM. Argh, no wonder then that [*students*](http://www.boston.com/news/nation/articles/2010/09/27/are_we_raising_a_generation_of_nincompoops/?page=full) generally don't RTFM. They really should... :-)
Alf P. Steinbach
+1  A: 

Check out System.IO.Path.GetDirectoryName on MSDN

http://msdn.microsoft.com/en-us/library/system.io.path.getdirectoryname.aspx

String^ folderName = System::IO::Path::GetDirectoryName(filestring);

beezler