更新记录

本文迁移自Panda666原博客,原发布时间:2021年6月30日。

一、说明

每种平台都其预定义的规则,比如Windows平台有自己的规定、公司也有预定义的规章制度。那么在平台上开发和干活,就要遵守人家的约定进行工作。当然,叛逆的你也可以不按约定出牌。常用Windows系统的小伙伴,通过GUI操作系统常用的路径基本大家都熟悉。下面通过编程的方式获得系统的常见路径。

二、使用Environment类型

直接Environment静态类型的GetFolderPath()方法即可获得许多预定义的Windows常见路径。

通过在Visual Studio中F12查看类型,可以看到详细的枚举定义。

实例具体如下:

//获得桌面所在的路径(虚拟)
Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
//获得桌面所在的路径(实际)
Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)
//获得启动下的应用程序目录
Console.WriteLine(Environment.GetFolderPath(Environment.SpecialFolder.Programs)
//获得我的文档路径
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
//获得我的文档路径
Environment.GetFolderPath(Environment.SpecialFolder.Personal)
//获得我最喜欢路径
Environment.GetFolderPath(Environment.SpecialFolder.Favorites)
//获得开启启动程序存放的目录
Environment.GetFolderPath(Environment.SpecialFolder.Startup)
//获得开启启动程序存放的目录(所有用户可见)
Environment.GetFolderPath(Environment.SpecialFolder.CommonStartup)
//获得用户最近使用的目录
Environment.GetFolderPath(Environment.SpecialFolder.Recent)
//获得菜单项目录
Environment.GetFolderPath(Environment.SpecialFolder.SendTo)
//获得开始菜单目录
Environment.GetFolderPath(Environment.SpecialFolder.StartMenu)
//获得开始菜单上的目录(所有用户可见)
Environment.GetFolderPath(Environment.SpecialFolder.CommonStartMenu)
//获得我的音乐目录
Environment.GetFolderPath(Environment.SpecialFolder.MyMusic)
//获得我的视频目录
Environment.GetFolderPath(Environment.SpecialFolder.MyVideos)
//我的图片所在目录
Environment.GetFolderPath(Environment.SpecialFolder.MyPictures)
//获得网络虚拟文件夹所在目录
Environment.GetFolderPath(Environment.SpecialFolder.NetworkShortcuts)
//获得字体所在目录
Environment.GetFolderPath(Environment.SpecialFolder.Fonts)
//获得模板目录
Environment.GetFolderPath(Environment.SpecialFolder.Templates)
//获得模板文件目录(所有用户可见)
Environment.GetFolderPath(Environment.SpecialFolder.CommonTemplates)
//获得桌面所在目录(所有用户可见)
Environment.GetFolderPath(Environment.SpecialFolder.CommonDesktopDirectory)
//获得应用数据所在目录(带同步)
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
//获得应用数据所在目录(本地用户)
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
//获得[internet]网络临时文件所在目录
Environment.GetFolderPath(Environment.SpecialFolder.InternetCache)
//获得[internet]网络Cookie所在目录
Environment.GetFolderPath(Environment.SpecialFolder.Cookies)
//获得[internet]浏览历史记录
Environment.GetFolderPath(Environment.SpecialFolder.History)
//获得应用数据所在目录
Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)
//Windows所在目录
//%windir% or %SYSTEMROOT%
Environment.GetFolderPath(Environment.SpecialFolder.Windows)
//System所在目录
Environment.GetFolderPath(Environment.SpecialFolder.System)
//System所在目录(x86)
Environment.GetFolderPath(Environment.SpecialFolder.SystemX86)
//Program Files所在目录
Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)
//Program Files所在目录(x86)
Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86)
//当前用户配置文件顶层所在目录
Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)
//应用程序共享文件所在目录
Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFiles)
//应用程序共享文件所在目录(x86)
Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFilesX86)
//公用文档目录
Environment.GetFolderPath(Environment.SpecialFolder.CommonDocuments)
//公用音乐目录
Environment.GetFolderPath(Environment.SpecialFolder.CommonMusic)
//公用图片目录
Environment.GetFolderPath(Environment.SpecialFolder.CommonPictures)
//公用视频目录
Environment.GetFolderPath(Environment.SpecialFolder.CommonVideos)

最新文章

  1. 【javascript进阶】异常
  2. HTTP Session原理
  3. 问题解决The connection to adb is down, and a severe error has occured.
  4. [AIR] AS3.0设置屏保功能
  5. dede 最近一天发布的文章标题前加hot
  6. 查询数据库返回List<Entity>问题
  7. google base 之MessagePumpForUI
  8. Java计算两个程序运行时间
  9. JQuery判断是否为空
  10. 用Jmeter实现SQLServer数据库的增删查改
  11. SpringBoot报错:nested exception is org.apache.ibatis.executor.ExecutorException: No constructor found in com.tuyrk.test.User matching [java.lang.Long, java.lang.String, java.lang.String]
  12. 使用VMware 虚拟linux系统环境
  13. Javaweb过滤器
  14. sql server 转置 和实现随机分配和一串代码的含义拼在一行
  15. Spring的编程式事务和声明式事务
  16. hdoj-1114 (背包dp)
  17. Linux中Sed的用法
  18. Linux下Oracle中SqlPlus时上下左右键乱码问题的解决办法
  19. 用jquery实现带左右按键的轮播图
  20. UEFI下windows启动过程

热门文章

  1. Java中最早期的集合Vector
  2. linux磁盘之分区类型id
  3. QT-守护程序
  4. 初识ES6(JavaScript)
  5. 在vue项目中配置webpack
  6. JavaScript基础第04天笔记
  7. 基础设施即代码(IAC),Zalando Postgres Operator UI 入门
  8. [源码解析] TensorFlow 分布式之 MirroredStrategy
  9. 震惊!<string.h>、<cstring>和<string>竟然可以这么用!
  10. Nginx作为高性能服务器的缘由以及请求过程