.net中的目录
System.Environment.CurrentDirectory
Application.StartupPath
https://msdn.microsoft.com/en-us/library/system.windows.forms.application.startuppath(v=vs.110).aspx
System.Environment.CurrentDirectory
https://msdn.microsoft.com/en-us/library/system.environment.currentdirectory(v=vs.110).aspx
百度之后,找到区别
System.Environment.CurrentDirectory的含义是获取或设置当前工作路径,
而Application.StartupPath是获取程序启动路径,
表面上看二者没什么区别,但实际上区别大得很。
先说前者:比如说你程序放在桌面上启动,但是中间你用了一个OpenFileDialog打开了E盘名为abc的文件夹下的某一个文件,那么CurrentDirectory就变成E:\abc了,
所以如果你想再获取程序启动文件夹的某一个文件就没用了,
但是Application.StartupPath就不会这样了,无论你中间打开了哪个盘的文件,启动路径都是在桌面那里,一直不会变。
If you want to get the path to the directory under which your executable runs, you should not rely on the Environment.CurrentDirectory,
since it can be changed in a number of ways (shotrtcut settings, etc). Try one of these options instead:
http://stackoverflow.com/questions/1321628/environment-currentdirectory-in-c-net
You shouldn't be using the Environment.CurrentDirectory value as a base for file lookups because it can change and may not always be under your control. e.g. a File Save As to a different folder may change the 'current folder' value. As you can see it can yield unpredictable results.
Use a value that you can control better. e.g. a ResourcesFolderPath value in a configuration (xml?) file that is updated when you install your app.
Desktop 和 DesktopDirectory
https://msdn.microsoft.com/en-us/library/system.environment.specialfolder(v=vs.110).aspx
Desktop :The logical Desktop rather than the physical file system location.
DesktopDirectory:he directory used to physically store file objects on the desktop.
What's the difference between SpecialFolder.Desktop and SpecialFolder.DesktopDirectory?
A directory is a location in the file system.
A folder is a location in the shell namespace.
A directory is a kind of folder.
A virtual folder is not necessarily backed by a directory.
For example consider libraries or search folders.
The user's desktop directory is a location in the file system.
The desktop folder merges that with virtual items like all users items, recycle bin, shortcut to documents folder etc.
.net中的目录的更多相关文章
- Dedecms去掉URL中a目录的方法
本文实例讲述了Dedecms去掉URL中a目录的方法.分享给大家,供大家参考.具体分析如下: 使用dedecms的朋友可能会发现自己的URL目录生成是会自动带有一个/A/目录了,那么要如何去掉URL中 ...
- linux下截取给定路径中的目录部分
在日常运维中,有时会要求截取一个路径中的目录部分.截取目录的方法,有以下两种:1)dirname命令(最常用的方法):用于取给定路径的目录部分.很少直接在shell命令行中使用,一般把它用在shell ...
- Twitter Storm源代码分析之ZooKeeper中的目录结构
徐明明博客:Twitter Storm源代码分析之ZooKeeper中的目录结构 我们知道Twitter Storm的所有的状态信息都是保存在Zookeeper里面,nimbus通过在zookeepe ...
- Linux中/proc目录下文件详解
转载于:http://blog.chinaunix.net/uid-10449864-id-2956854.html Linux中/proc目录下文件详解(一)/proc文件系统下的多种文件提供的系统 ...
- IntelliJ和tomcat中的目录结构
IntelliJ和tomcat中的目录结构 IntelliJ的官网帮助中心:http://www.jetbrains.com/idea/webhelp/getting-help.html pr ...
- dirname basename 截取路径中的目录以及文件名
dirname basename 截取路径中的目录以及文件名 windows 下面: #include "shlwapi.h"#pragma comment(lib, &qu ...
- PHP dirname() 返回路径中的目录部分basename() 函数返回路径中的文件名部分。
dirname (PHP 4, PHP 5) dirname — 返回路径中的目录部分说明string dirname ( string $path ) 给出一个包含有指向一个文件的全路径的字符串,本 ...
- nginx中针对目录进行IP限制
一个不错的nginx中针对目录进行IP限制 ,这里我以phpmyadmin目录只能让内网IP访问,而外网不能访问的配置方法,有需要的同学可参考. nginx phpmyadmin 针对内网ip用户开放 ...
- Android 获取SDCard中某个目录下图片
本文介绍Android开发中如何获取SDCard中某目录下的所有图片并显示出来,下面的我们提供的这个函数是通用的,只要提供路径就可以查询出该目录下所有图片的路径信息,并保存到一个List<Str ...
- Linux中一些目录名称的含义
挖Linux中的古老缩略语[2005-06-22 15:23][Nigel McFarlane][TechTarget] Unix已经有35年历史了.许多人认为它开始于中世纪,这个中世纪是相对于计算机 ...
随机推荐
- 本地 配置 Memcache
如果帮到了您,可以支持一下,谢谢您的支持! Windows下的Memcache安装: 64bit:如果需要win64版,下载 memcached-win64-1.4.4-14.zip(直接下),里面有 ...
- Codeforces Round #338 (Div. 2) B. Longtail Hedgehog 记忆化搜索/树DP
B. Longtail Hedgehog This Christmas Santa gave Masha a magic picture and a pencil. The picture con ...
- composer的一些操作
版本更新 命令行下:composer self-update 设置中国镜像 composer config -g repo.packagist composer https://packagist.p ...
- WebApi不支持跨域访问
- WIN7把任务栏的的蓝牙图标误删了找回方法
当时我删了以后,在网上找方法,都说—— 点击任务栏下面的三角箭头,选择自定义,里面有蓝牙图标选项,选择显示图标和通知. 可是我发现我的自定义选项里面就没有蓝牙图标选项啊... 故事的最后,我终于找到了 ...
- Hibernate框架学习(七)——多对多关系
一.关系表达 1.表中的表达 2.实体中的表达 3.orm元数据中的表达 在User.hbm.xml中添加: 在Role.hbm.xml中添加(与上相反): 二.操作关联属性 1.保存员工及角色 pu ...
- JPush设置别名不走成功回调的解决办法
在参考了极光推送的文档之后,对个推(单个推送)有设置别名的方法,方法如下 [JPUSHService setTags:tags alias:alias fetchCompletionHandle:^( ...
- 防范CSRF(三)
除了可以更改微软默认的cookie的名字外,还可以更改默认的加密方法.继承IAntiForgeryAdditionalDataProvider接口,实现里面的方法即可. 采用的加密方法有加盐和使用时间 ...
- Git 版本控制原理
git 工作原理图 如上图所示,有三个区域Working Directory.stage.master. 名词解释: 工作区(Working Directory) 在我们直接编辑文件(文件夹)的根目录 ...
- ZBrush软件特性之Color调控板
ZBrush®中的Color调色板显示当前颜色并提供数值的方法选择颜色,而且选择辅助色,使用描绘工具可以产生混合的色彩效果. ZBrush 4R8下载:http://wm.makeding.com/i ...