// PathGetDirectoryName.cpp : メイン プロジェクト ファイルです。 #include "stdafx.h" using namespace System; using namespace System::IO; void PathGetDirectoryName(void) { // 親ディレクトリ名 (フォルダ名) を取得する String^ stParentName = Path::GetDirectoryName( "C:\\MyFolder\\Homepage\\public_html\\Cprpr\\GetDirectoryNamePath\\GetDirectoryNamePath.txt"); // 親ディレクトリ名 (フォルダ名) を表示する Console::WriteLine(stParentName); // 指定したパスから親ディレクトリの DirectoryInfo を取得する DirectoryInfo^ hDirInfo = Directory::GetParent( "C:\\MyFolder\\Homepage\\public_html\\Cprpr\\GetDirectoryNamePath\\GetDirectoryNamePath.txt"); // 親ディレクトリの名前を表示する Console::WriteLine(hDirInfo->FullName); // FileInfo の新しいインスタンスを生成する FileInfo^ cFileInfo = gcnew FileInfo( "C:\\MyFolder\\Homepage\\public_html\\Cprpr\\GetDirectoryNamePath\\GetDirectoryNamePath.txt"); // FileInfo から親ディレクトリの DirectoryInfo を取得する DirectoryInfo^ hDirInfo2 = cFileInfo->Directory; // 親ディレクトリの名前を表示する Console::WriteLine(hDirInfo2->FullName); // DirectoryInfo の新しいインスタンスを生成する DirectoryInfo^ hDirInfoBar = gcnew DirectoryInfo( "C:\\MyFolder\\Homepage\\public_html\\Cprpr\\GetDirectoryNamePath\\GetDirectoryNamePath.txt"); // DirectoryInfo から親ディレクトリの DirectoryInfo を取得する DirectoryInfo^ hDirInfo3 = hDirInfoBar->Parent; // 親ディレクトリの名前を表示する Console::WriteLine(hDirInfo3->FullName); // FileInfo の新しいインスタンスを生成する FileInfo^ cFileInfo2 = gcnew FileInfo( "C:\\MyFolder\\Homepage\\public_html\\Cprpr\\GetDirectoryNamePath\\GetDirectoryNamePath.txtt"); // FileInfo から親ディレクトリの名前を取得する String^ stParentName2 = cFileInfo2->DirectoryName; // 親ディレクトリの名前を表示する Console::WriteLine(stParentName2); } int main(array ^args) { PathGetDirectoryName(); return 0; }