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就不会这样了,无论你中间打开了哪个盘的文件,启动路径都是在桌面那里,一直不会变。

http://stackoverflow.com/questions/1343406/environment-currentdirectory-is-yielding-unexpected-results-when-running-install

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中的目录的更多相关文章

  1. Dedecms去掉URL中a目录的方法

    本文实例讲述了Dedecms去掉URL中a目录的方法.分享给大家,供大家参考.具体分析如下: 使用dedecms的朋友可能会发现自己的URL目录生成是会自动带有一个/A/目录了,那么要如何去掉URL中 ...

  2. linux下截取给定路径中的目录部分

    在日常运维中,有时会要求截取一个路径中的目录部分.截取目录的方法,有以下两种:1)dirname命令(最常用的方法):用于取给定路径的目录部分.很少直接在shell命令行中使用,一般把它用在shell ...

  3. Twitter Storm源代码分析之ZooKeeper中的目录结构

    徐明明博客:Twitter Storm源代码分析之ZooKeeper中的目录结构 我们知道Twitter Storm的所有的状态信息都是保存在Zookeeper里面,nimbus通过在zookeepe ...

  4. Linux中/proc目录下文件详解

    转载于:http://blog.chinaunix.net/uid-10449864-id-2956854.html Linux中/proc目录下文件详解(一)/proc文件系统下的多种文件提供的系统 ...

  5. IntelliJ和tomcat中的目录结构

    IntelliJ和tomcat中的目录结构   IntelliJ的官网帮助中心:http://www.jetbrains.com/idea/webhelp/getting-help.html   pr ...

  6. dirname basename 截取路径中的目录以及文件名

    dirname basename    截取路径中的目录以及文件名 windows 下面: #include "shlwapi.h"#pragma comment(lib, &qu ...

  7. PHP dirname() 返回路径中的目录部分basename() 函数返回路径中的文件名部分。

    dirname (PHP 4, PHP 5) dirname — 返回路径中的目录部分说明string dirname ( string $path ) 给出一个包含有指向一个文件的全路径的字符串,本 ...

  8. nginx中针对目录进行IP限制

    一个不错的nginx中针对目录进行IP限制 ,这里我以phpmyadmin目录只能让内网IP访问,而外网不能访问的配置方法,有需要的同学可参考. nginx phpmyadmin 针对内网ip用户开放 ...

  9. Android 获取SDCard中某个目录下图片

    本文介绍Android开发中如何获取SDCard中某目录下的所有图片并显示出来,下面的我们提供的这个函数是通用的,只要提供路径就可以查询出该目录下所有图片的路径信息,并保存到一个List<Str ...

  10. Linux中一些目录名称的含义

    挖Linux中的古老缩略语[2005-06-22 15:23][Nigel McFarlane][TechTarget] Unix已经有35年历史了.许多人认为它开始于中世纪,这个中世纪是相对于计算机 ...

随机推荐

  1. CF149D 区间dp

    http://codeforces.com/problemset/problem/149/D D. Coloring Brackets time limit per test 2 seconds me ...

  2. Linux Mint (应用软件— 虚拟机:Virtualbox续)

    我已经在当前的电脑中安装好了虚拟机.并且在虚拟机中安装了Ubuntu14.04LTS系统.接下来能够開始自己的折腾之旅了. 開始使用的时候总是感觉显示有问题,根据经验来看同,是系统分辨率设置不当引起的 ...

  3. intellij idea 运行jedis

    到这里下载 http://mvnrepository.com/ jar包! 将jar包放入项目目录中,并引入! 引入包到项目中!创建对象! package com.company; import re ...

  4. UINavi中push控制器的时候隐藏TabBar

    当一个UITabbarController管理多个UINavigationController的时候,我们又从这每一个UINavigationController中push一个ViewControll ...

  5. centos 出现的问题

    1.DNS问题,导致yum没得源 echo "nameserver 8.8.8.8">>/etc/resolv.conf 2.CentOS 7最小化安装后找不到‘ifc ...

  6. DateTime? 定义的日期变量如何format

    DateTime? dateTime; dateTime.Value.ToString("yy-MM-dd")

  7. intell-

    intellect: n.[U, C] the ability to think in a logical way and understand things, especially at an ad ...

  8. TCP基本概念

    TCP协议是一个复杂的.可靠的字节流协议.不通用UDP协议. TCP提供客户与服务器之间的连接.TCP客户先与给定的服务器建立一个连接,再跨该连接与服务器交换数据,最后终止这个连接. TCP提供了可靠 ...

  9. GCD与dispatch_group总结

    GCD 可以看作是集合类的操作: 集合是queue,元素是block: 集合只能添加对象,删除对象由系统完成. 同理,NSOperationQueue也可以看作是一个集合管理器. dispatch_g ...

  10. 使用node+mysql进行后端开发

    使用koa: koa2是一个类,所以引入koa后,要创建实例化“对象”,才能使用koa内部封装的方法. 设置监听端口: 处理http请求: 1.http请求处理链 A.通过app.use()注册asy ...