 その他の特殊ディレクトリまでのパスを取得する
その他の特殊ディレクトリまでのパスを取得する
					
スポンサーリンク
特殊ディレクトリまでのパスを取得するには、System.Environment クラスの GetFolderPath メソッドを使用します。GetFolderPath メソッドは、特殊ディレクトリの種類を示す SpecialFolder 列挙体を指定することでそのディレクトリまでのパスが返されます。
サンプルコード
以下にサンプルコードを示します。
C# 全般
    // System ディレクトリ
    MessageBox.Show(System.Environment.GetFolderPath(System.Environment.SpecialFolder.System));
    // Program Files ディレクトリ
    MessageBox.Show(System.Environment.GetFolderPath(System.Environment.SpecialFolder.ProgramFiles));
    // マイ コンピュータ (実際は、取得できません)
    MessageBox.Show(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyComputer));
    // マイ ドキュメント
    MessageBox.Show(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal));
    // マイ ピクチャ
    MessageBox.Show(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyPictures));
    // マイ ミュージック
    MessageBox.Show(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyPictures));
    // 論理的に使用されるデスクトップ ディレクトリ
    MessageBox.Show(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop));
    // 物理的に使用されるデスクトップ ディレクトリ (前行と混同しないこと)
    MessageBox.Show(System.Environment.GetFolderPath(System.Environment.SpecialFolder.DesktopDirectory));
    // [スタート メニュー] のプログラム グループを格納するディレクトリ
    MessageBox.Show(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Programs));
    // [スタート アップ] プログラム グループに対応するディレクトリ
    MessageBox.Show(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Startup));
    // [スタート] メニュー項目を格納するディレクトリ
    MessageBox.Show(System.Environment.GetFolderPath(System.Environment.SpecialFolder.StartMenu));
    // [送る] メニュー項目を格納するディレクトリ
    MessageBox.Show(System.Environment.GetFolderPath(System.Environment.SpecialFolder.SendTo));
    // お気に入り
    MessageBox.Show(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Favorites));
    // 最近使用したファイル
    MessageBox.Show(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Recent));
    // インターネットの履歴
    MessageBox.Show(System.Environment.GetFolderPath(System.Environment.SpecialFolder.History));
    // インターネット キャッシュ
    MessageBox.Show(System.Environment.GetFolderPath(System.Environment.SpecialFolder.InternetCache));
    // ドキュメント テンプレート
    MessageBox.Show(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Templates));
    // アプリケーション間で共有されるコンポーネント用のディレクトリ
    MessageBox.Show(System.Environment.GetFolderPath(System.Environment.SpecialFolder.CommonProgramFiles));
    // すべてのユーザーが使用するアプリケーション固有のデータの共通リポジトリとして機能するディレクトリ
    MessageBox.Show(System.Environment.GetFolderPath(System.Environment.SpecialFolder.CommonApplicationData));
    // ローミング ユーザーのアプリケーション固有のデータの共通リポジトリとして機能するディレクトリ
    MessageBox.Show(System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData));
    // 非ローミング ユーザーのアプリケーション固有のデータの共通リポジトリとして機能するディレクトリ
    MessageBox.Show(System.Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData));
関連するリファレンス
準備中です。
