Get parent directory of file as string c++
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.
You can use the FullName property:
System::String^ directoryFullName=Directory::GetParent(filestring)->FullName;
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.
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);
精彩评论