开发者

Get parent directory of file as string c++

开发者 https://www.devze.com 2023-01-20 07:18 出处:网络
I\'m using Managed C++. I need to extract the parent directoryafter OpenFileDialog returns the String^ file path.

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);

0

精彩评论

暂无评论...
验证码 换一张
取 消