.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年历史了.许多人认为它开始于中世纪,这个中世纪是相对于计算机 ...
随机推荐
- openssl之BIO系列之24---SSL类型的BIO
SSL类型的BIO ---依据openssl doc\crypto\bio_f_ssl.pod翻译和自己的理解写成 (作者:DragonKing, Mail: wzhah@263.net ,公布于:h ...
- 使用VMware搭建3台一模一样的Linux虚拟机
转自:https://www.linuxidc.com/Linux/2014-08/105909.htm 简介:VMware可以在个人本地一台笔记本机器上同时运行二个或更多Windows.DOS.LI ...
- 迭代Iterator的用法
迭代→遍历: 一个标准化遍历各类容器里面的所有对象的方法类(典型的设计模式) 把访问逻辑从不同类型的集合类中抽象出来,从而避免向客户端暴露集合的内部结构 迭代(Iterator)与枚举(Enumera ...
- IBM 总架构师:话说程序员的职业生涯
作者:IBM 软件集团大中华区总架构师 寇卫东 有一些年轻的程序员向我咨询,将来的路应该怎么走?俗话说,条条大路通罗马.不同的路都能走向成功.到底选哪条路,取决于自己的兴趣.可能有程序员会问:如果还没 ...
- 打包phar文件过大的问题。
根据一个开源工具得到的灵感,使用流打包,并使用token_get_all移除了所用PHP文件的空白.现在打包出来只有93k了.谢谢关注. 我一个简单的文件,加上一个symfony的process包,打 ...
- GCC中的弱符号与强符号
GCC中的弱符号与强符号 我们经常在编程中碰到一种情况叫符号重复定义.多个目标文件中含有相同名字全局符号的定义,那么这些目标文件链接的时候将会出现符号重复定义的错误.比如我们在目标文件A和目标文件B都 ...
- Qwiklab'实验-CloudFront, EFS, S3'
title: AWS之Qwiklab subtitle: 3. Qwiklab'实验-CloudFront, EFS, S3' date: 2018-09-21 17:29:20 --- Introd ...
- bzoj 3028: 食物 生成函数_麦克劳林展开
不管怎么求似乎都不太好求,我们试试生成函数.这个东西好神奇.生成函数的精华是两个生成函数相乘,对应 $x^{i}$ 前的系数表示取 $i$ 个时的方案数. 有时候,我们会将函数按等比数列求和公式进行压 ...
- Pyhton学习——Day4
'''y=2*x+1x=3y->7x=3y->7'''# def test(x):# '''# 2*x+1# :param x:整形数字# :return: 返回计算结果# '''# y= ...
- 《Exception》第八次团队作业:Alpha冲刺(第三天)
一.项目基本介绍 项目 内容 这个作业属于哪个课程 任课教师博客主页链接 这个作业的要求在哪里 作业链接地址 团队名称 Exception 作业学习目标 1.掌握软件测试基础技术.2.学习迭代式增 ...