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. 多线程编程TSL相关的技术文档

    线程本地存储 (TLS) https://msdn.microsoft.com/zh-cn/library/6yh4a9k1(v=vs.80).aspx Using Thread Local Stor ...

  2. pyspark MLlib踩坑之model predict+rdd map zip,zip使用尤其注意啊啊啊!

    Updated:use model broadcast, mappartition+flatmap,see: from pyspark import SparkContext import numpy ...

  3. nyoj--1185--最大最小值(线段树)

    最大最小值 时间限制:1000 ms  |  内存限制:65535 KB 难度:2 描述 给出N个整数,执行M次询问. 对于每次询问,首先输入三个整数C.L.R: 如果C等于1,输出第L个数到第R个数 ...

  4. 2.linux系统命令详解

    1 shell shell:命令解释器,根据输入的命令执行相应命令. 1.1 shell家族 察看当前系统下有哪些shell: cat /etc/shells 察看当前系统正在使用的shell ech ...

  5. 简述RNN Recurrent Neural Networks

    本文结构: 什么是 Recurrent Neural Networks ? Recurrent Neural Networks 的优点和应用? 训练 Recurrent Neural Networks ...

  6. SwipeRefreshLayout的使用,下拉刷新

    1. <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android ...

  7. python模拟登陆知乎

    ---恢复内容开始--- 在完成前面的阶段的任务之后,我们现在已经能够尝试着去模拟登录一些网站了.在这里我们模拟登录一下知乎做一下实验.笔者在这里总共用了三天多的时间,下面给大家分享一下笔者是怎么一步 ...

  8. OpenCV3 安装

    Opencv 安装 本文主要说明了在ubuntu上通过源码安装Opencv3,包含各种独立接口.具体可以参照LearnOpencv: https://www.learnopencv.com/insta ...

  9. hdu 3549 Flow Problem 【最大流】

    其实还是不是很懂dinic----- 抄了一个模板--- http://www.cnblogs.com/naturepengchen/articles/4403408.html 先放在这里--- #i ...

  10. Maven编译、打war包

    Eclipse环境,每次alt+F5刷新Maven项目时,总是会把项目的Java依赖刷新成1.5. 解决办法:在pom中加入如下片段 <plugin> <groupId>org ...