酢ろぐ!

カレーが嫌いなスマートフォンアプリプログラマのブログ。

Xamarin.iOSでフォルダのパスを取得する

.NET FrameworkではEnvironment.GetFolderPathメソッドを使うことでフォルダパスを取得することができます。Xamarin.iOSをiPhoneシミュレータで実行した場合に取得できるフォルダパスを調べてみました。

string dir = string.Empty;
dir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
Console.WriteLine("ApplicationData :{0}", dir);

dir = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
Console.WriteLine("CommonApplicationData :{0}", dir);

dir = Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFiles);
Console.WriteLine("CommonProgramFiles :{0}", dir);

dir = Environment.GetFolderPath(Environment.SpecialFolder.Cookies);
Console.WriteLine("Cookies :{0}", dir);

dir = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
Console.WriteLine("Desktop :{0}", dir);

dir = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
Console.WriteLine("DesktopDirectory :{0}", dir);

dir = Environment.GetFolderPath(Environment.SpecialFolder.Favorites);
Console.WriteLine("Favorites :{0}", dir);

dir = Environment.GetFolderPath(Environment.SpecialFolder.History);
Console.WriteLine("History :{0}", dir);

dir = Environment.GetFolderPath(Environment.SpecialFolder.InternetCache);
Console.WriteLine("InternetCache :{0}", dir);

dir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
Console.WriteLine("LocalApplicationData :{0}", dir);

dir = Environment.GetFolderPath(Environment.SpecialFolder.MyComputer);
Console.WriteLine("MyComputer :{0}", dir);

dir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
Console.WriteLine("MyDocuments :{0}", dir);

dir = Environment.GetFolderPath(Environment.SpecialFolder.MyMusic);
Console.WriteLine("MyMusic :{0}", dir);

dir = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
Console.WriteLine("MyPictures :{0}", dir);

dir = Environment.GetFolderPath(Environment.SpecialFolder.MyVideos);
Console.WriteLine("MyVideos :{0}", dir);

dir = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
Console.WriteLine("Personal :{0}", dir);

dir = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
Console.WriteLine("ProgramFiles :{0}", dir);

dir = Environment.GetFolderPath(Environment.SpecialFolder.Programs);
Console.WriteLine("Programs :{0}", dir);

dir = Environment.GetFolderPath(Environment.SpecialFolder.Recent);
Console.WriteLine("Recent :{0}", dir);

dir = Environment.GetFolderPath(Environment.SpecialFolder.SendTo);
Console.WriteLine("SendTo :{0}", dir);

dir = Environment.GetFolderPath(Environment.SpecialFolder.StartMenu);
Console.WriteLine("StartMenu :{0}", dir);

dir = Environment.GetFolderPath(Environment.SpecialFolder.Startup);
Console.WriteLine("Startup :{0}", dir);

dir = Environment.GetFolderPath(Environment.SpecialFolder.System);
Console.WriteLine("System :{0}", dir);

dir = Environment.GetFolderPath(Environment.SpecialFolder.Templates);
Console.WriteLine("Templates :{0}", dir);

上記のコードを実行してみました。%SIM_DIR%はiPhoneシミュレータのアプリケーションがインストールされているまでのフォルダパスを示します。

ApplicationData : %SIM_DIR%/Applications/56382C92-A0E3-46E8-AD02-3778312AEF16/Documents/.config
CommonApplicationData :/usr/share
CommonProgramFiles :
Cookies :
Desktop :%SIM_DIR%/Applications/56382C92-A0E3-46E8-AD02-3778312AEF16/Desktop
DesktopDirectory :%SIM_DIR%/Applications/56382C92-A0E3-46E8-AD02-3778312AEF16/Desktop
Favorites :%SIM_DIR%/Applications/56382C92-A0E3-46E8-AD02-3778312AEF16/Library/Favorites
History :
InternetCache :%SIM_DIR%/Applications/56382C92-A0E3-46E8-AD02-3778312AEF16/Library/Caches
LocalApplicationData :%SIM_DIR%/Applications/56382C92-A0E3-46E8-AD02-3778312AEF16/Documents
MyComputer :
MyDocuments :%SIM_DIR%/Applications/56382C92-A0E3-46E8-AD02-3778312AEF16/Documents
MyMusic :%SIM_DIR%/Applications/56382C92-A0E3-46E8-AD02-3778312AEF16/Music
MyPictures :%SIM_DIR%/Applications/56382C92-A0E3-46E8-AD02-3778312AEF16/Pictures
MyVideos :%SIM_DIR%/Applications/56382C92-A0E3-46E8-AD02-3778312AEF16/Videos
Personal :%SIM_DIR%/Applications/56382C92-A0E3-46E8-AD02-3778312AEF16/Documents
ProgramFiles :/Applications
Programs :
Recent :
SendTo :
StartMenu :
Startup :
System :
Templates :%SIM_DIR%/Applications/56382C92-A0E3-46E8-AD02-3778312AEF16/Templates

Environment.SpecialFolder列挙体と取得できるフォルダパスの対応表は以下の通りです。

SpecialFolder.ApplicationData %SIM_DIR%/Applications/56382C92-A0E3-46E8-AD02-3778312AEF16/Documents/.config
SpecialFolder.CommonApplicationData /usr/share
SpecialFolder.CommonProgramFiles
SpecialFolder.Cookies
SpecialFolder.Desktop %SIM_DIR%/Applications/56382C92-A0E3-46E8-AD02-3778312AEF16/Desktop
SpecialFolder.DesktopDirectory %SIM_DIR%/Applications/56382C92-A0E3-46E8-AD02-3778312AEF16/Desktop
SpecialFolder.Favorites %SIM_DIR%/Applications/56382C92-A0E3-46E8-AD02-3778312AEF16/Library/Favorites
SpecialFolder.History
SpecialFolder.InternetCache %SIM_DIR%/Applications/56382C92-A0E3-46E8-AD02-3778312AEF16/Library/Caches
SpecialFolder.LocalApplicationData %SIM_DIR%/Applications/56382C92-A0E3-46E8-AD02-3778312AEF16/Documents
SpecialFolder.MyComputer
SpecialFolder.MyDocuments %SIM_DIR%/Applications/56382C92-A0E3-46E8-AD02-3778312AEF16/Documents
SpecialFolder.MyMusic %SIM_DIR%/Applications/56382C92-A0E3-46E8-AD02-3778312AEF16/Music
SpecialFolder.MyPictures %SIM_DIR%/Applications/56382C92-A0E3-46E8-AD02-3778312AEF16/Pictures
SpecialFolder.MyVideos %SIM_DIR%/Applications/56382C92-A0E3-46E8-AD02-3778312AEF16/Videos
SpecialFolder.Personal %SIM_DIR%/Applications/56382C92-A0E3-46E8-AD02-3778312AEF16/Documents
SpecialFolder.ProgramFiles /Applications
SpecialFolder.Programs
SpecialFolder.Recent
SpecialFolder.SendTo
SpecialFolder.StartMenu
SpecialFolder.Startup
SpecialFolder.System
SpecialFolder.Templates %SIM_DIR%/Applications/56382C92-A0E3-46E8-AD02-3778312AEF16/Templates