.net c#中 Environment.SpecialFolder 枚举包含了系统内置的特定路径.
根据该枚举,然后通过Environment的GetFolderPath方法获取详细目录信息
源码如下:
#region 系统内特殊的路径信息
/// <summary>
/// 系统内特殊的路径信息
/// </summary>
/// <returns></returns>
public string SysDir()
{
StringBuilder str = new StringBuilder();
//特殊目录
string[] names = Enum.GetNames(typeof(Environment.SpecialFolder));
foreach (string name in names)
{
Environment.SpecialFolder sf;
if (Enum.TryParse<Environment.SpecialFolder>(name, out sf))
{
string folder = Environment.GetFolderPath(sf);
str.AppendLine(string.Format("{0}: {1}", name, folder));
}
}
return str.ToString();
}
#endregion
执行结果:
Desktop: C:\Users\Administrator\Desktop
Programs: C:\Users\Administrator\AppData\Roaming\Microsoft\Windows\Start Menu\Programs
MyDocuments: C:\Users\Administrator\Documents
Personal: C:\Users\Administrator\Documents
Favorites: C:\Users\Administrator\Favorites
Startup: C:\Users\Administrator\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
Recent: C:\Users\Administrator\AppData\Roaming\Microsoft\Windows\Recent
SendTo: C:\Users\Administrator\AppData\Roaming\Microsoft\Windows\SendTo
StartMenu: C:\Users\Administrator\AppData\Roaming\Microsoft\Windows\Start Menu
MyMusic: C:\Users\Administrator\Music
MyVideos: C:\Users\Administrator\Videos
DesktopDirectory: C:\Users\Administrator\Desktop
MyComputer:
NetworkShortcuts: C:\Users\Administrator\AppData\Roaming\Microsoft\Windows\Network Shortcuts
Fonts: C:\WINDOWS\Fonts
Templates: C:\Users\Administrator\AppData\Roaming\Microsoft\Windows\Templates
CommonStartMenu: C:\ProgramData\Microsoft\Windows\Start Menu
CommonPrograms: C:\ProgramData\Microsoft\Windows\Start Menu\Programs
CommonStartup: C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup
CommonDesktopDirectory: C:\Users\Public\Desktop
ApplicationData: C:\Users\Administrator\AppData\Roaming
PrinterShortcuts: C:\Users\Administrator\AppData\Roaming\Microsoft\Windows\Printer Shortcuts
LocalApplicationData: C:\Users\Administrator\AppData\Local
InternetCache: C:\Users\Administrator\AppData\Local\Microsoft\Windows\INetCache
Cookies: C:\Users\Administrator\AppData\Local\Microsoft\Windows\INetCookies
History: C:\Users\Administrator\AppData\Local\Microsoft\Windows\History
CommonApplicationData: C:\ProgramData
Windows: C:\WINDOWS
System: C:\WINDOWS\system32
ProgramFiles: C:\Program Files (x86)
MyPictures: C:\Users\Administrator\Pictures
UserProfile: C:\Users\Administrator
SystemX86: C:\WINDOWS\SysWOW64
ProgramFilesX86: C:\Program Files (x86)
CommonProgramFiles: C:\Program Files (x86)\Common Files
CommonProgramFilesX86: C:\Program Files (x86)\Common Files
CommonTemplates: C:\ProgramData\Microsoft\Windows\Templates
CommonDocuments: C:\Users\Public\Documents
CommonAdminTools: C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Administrative Tools
AdminTools: C:\Users\Administrator\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Administrative Tools
CommonMusic: C:\Users\Public\Music
CommonPictures: C:\Users\Public\Pictures
CommonVideos: C:\Users\Public\Videos
Resources: C:\WINDOWS\resources
LocalizedResources: C:\WINDOWS\resources\0804
CommonOemLinks: C:\ProgramData\OEM Links
CDBurning: C:\Users\Administrator\AppData\Local\Microsoft\Windows\Burn\Burn
图片展示效果: