C#中得到程序当前工作目录和执行目录的五种方法
string str="";
str += "\r\n" + System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
str += "\r\n" + System.Environment.CurrentDirectory;
str += "\r\n" + System.IO.Directory.GetCurrentDirectory();
str += "\r\n" + System.AppDomain.CurrentDomain.BaseDirectory;
str += "\r\n" + System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
str += "\r\n" + System.Windows.Forms.Application.StartupPath;
str += "\r\n" + System.Windows.Forms.Application.ExecutablePath;
Console.Write(str);
Console.ReadKey();
得到结果:
D:\路径测试\bin\Debug\路径测试.vshost.exe
D:\路径测试\bin\Debug
D:\路径测试\bin\Debug
D:\路径测试\bin\Debug\
D:\路径测试\bin\Debug\
D:\路径测试\bin\Debug
D:\路径测试\bin\Debug\路径测试.EXE
1. System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName
获取模块的完整路径。
2. System.Environment.CurrentDirectory
获取和设置当前目录(该进程从中启动的目录)的完全限定目录。
3. System.IO.Directory.GetCurrentDirectory()
获取应用程序的当前工作目录。这个不一定是程序从中启动的目录啊,有可能程序放在C:\www里,这个函数有可能返回C:\Documents and Settings\ZYB\,或者C:\Program Files\Adobe\,有时不一定返回什么东东,我也搞不懂了。
4. System.AppDomain.CurrentDomain.BaseDirectory
获取程序的基目录。确认这种方法在 windows服务中是可以用的
5. System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase
获取和设置包括该应用程序的目录的名称。
6. System.Windows.Forms.Application.StartupPath
获取启动了应用程序的可执行文件的路径。效果和2、5一样。只是5返回的字符串后面多了一个"\"而已
7. System.Windows.Forms.Application.ExecutablePath
获取启动了应用程序的可执行文件的路径及文件名,效果有时和1一样。
C#中得到程序当前工作目录和执行目录的五种方法
string str="";
str += "\r\n" + System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
str += "\r\n" + System.Environment.CurrentDirectory;
str += "\r\n" + System.IO.Directory.GetCurrentDirectory();
str += "\r\n" + System.AppDomain.CurrentDomain.BaseDirectory;
str += "\r\n" + System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
str += "\r\n" + System.Windows.Forms.Application.StartupPath;
str += "\r\n" + System.Windows.Forms.Application.ExecutablePath;
Console.Write(str);
Console.ReadKey();
得到结果:
D:\路径测试\bin\Debug\路径测试.vshost.exe
D:\路径测试\bin\Debug
D:\路径测试\bin\Debug
D:\路径测试\bin\Debug\
D:\路径测试\bin\Debug\
D:\路径测试\bin\Debug
D:\路径测试\bin\Debug\路径测试.EXE
1. System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName
获取模块的完整路径。
2. System.Environment.CurrentDirectory
获取和设置当前目录(该进程从中启动的目录)的完全限定目录。
3. System.IO.Directory.GetCurrentDirectory()
获取应用程序的当前工作目录。这个不一定是程序从中启动的目录啊,有可能程序放在C:\www里,这个函数有可能返回C:\Documents and Settings\ZYB\,或者C:\Program Files\Adobe\,有时不一定返回什么东东,我也搞不懂了。
4. System.AppDomain.CurrentDomain.BaseDirectory
获取程序的基目录。确认这种方法在 windows服务中是可以用的
5. System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase
获取和设置包括该应用程序的目录的名称。
6. System.Windows.Forms.Application.StartupPath
获取启动了应用程序的可执行文件的路径。效果和2、5一样。只是5返回的字符串后面多了一个"\"而已
7. System.Windows.Forms.Application.ExecutablePath
获取启动了应用程序的可执行文件的路径及文件名,效果有时和1一样。
C#中得到程序当前工作目录和执行目录的五种方法的更多相关文章
- VC++ 获取系统时间、程序运行时间(精确到秒,毫秒)的五种方法
1.使用CTime类(获取系统当前时间,精确到秒) CString str; //获取系统时间 CTime tm; tm=CTime::GetCurrentTime();//获取系统日期 str=tm ...
- 【VS开发】VC++ 获取系统时间、程序运行时间(精确到秒,毫秒)的五种方法
1.使用CTime类(获取系统当前时间,精确到秒) CString str; //获取系统时间 CTime tm; tm=CTime::GetCurrentTime();//获取系统日期 str=tm ...
- JS中判断某个字符串是否包含另一个字符串的五种方法
String对象的方法 方法一: indexOf() (推荐) ? 1 2 var str = "123" console.log(str.indexOf("2&qu ...
- python中执行shell的两种方法总结
这篇文章主要介绍了python中执行shell的两种方法,有两种方法可以在Python中执行SHELL程序,方法一是使用Python的commands包,方法二则是使用subprocess包,这两个包 ...
- C#统计给定的文本中字符出现的次数,使用循环和递归两种方法
前几天看了一个.net程序员面试题目,题目是”统计给定的文本中字符出现的次数,使用循环和递归两种方法“. 下面是我对这个题目的解法: 1.使用循环: /// <summary> /// 使 ...
- Oracle中获取执行计划的几种方法分析
以下是对Oracle中获取执行计划的几种方法进行了详细的分析介绍,需要的朋友可以参考下 1. 预估执行计划 - Explain PlanExplain plan以SQL语句作为输入,得到这条S ...
- 在Activity中响应ListView内部按钮的点击事件的两种方法!!!
在Activity中响应ListView内部按钮的点击事件的两种方法 转载:http://www.cnblogs.com/ivan-xu/p/4124967.html 最近交流群里面有人问到一个问题: ...
- (网页)angular中实现li或者某个元素点击变色的两种方法(转)
转自脚本之家: 本篇文章主要介绍了angular中实现li或者某个元素点击变色的两种方法,非常具有实用价值,需要的朋友可以参考下 本文介绍了angular中实现li或者某个元素点击变色的两种方法,分享 ...
- SQL Server中灾难时备份结尾日志(Tail of log)的两种方法
转自:http://www.cnblogs.com/CareySon/archive/2012/02/23/2365006.html SQL Server中灾难时备份结尾日志(Tail of log) ...
随机推荐
- iOS Version和Build的区别
iOS开发中,会面对一个问题,Version和Build的区别.这两种均是版本号,但是在开发中还是有一定的区别,而且用处很大. Version 是版本号,在info.plist中对应的key是 CFB ...
- 短信利用weixin://connectToFreeWifi/?apKey=协议跳转到微信打开落地页h5
微信门店wifi接口,任意站跳转,跳转二维码长按识别加粉,接口支持动态传参数,支持微信支付等特殊接口对接. 代码如下使用 <head> <meta charset="utf ...
- [BZ4923][Lydsy1706月赛]K小值查询
K小值查询 题面 维护一个长度为n的正整数序列a_1,a_2,...,a_n,支持以下两种操作: 1 k,将序列a从小到大排序,输出a_k的值. 2 k,将所有严格大于k的数a_i减去k. Input ...
- Vue系列之 => MintUI初使用
安装 npm i mint-ui -S main.js import Vue from 'vue' // 1,导入 vue-router包 import vueRouter from 'vue-rou ...
- django signals 信号
django signals 信号 配置方式 app下的 __init__.py default_app_config="web.apps.WebConfig" #初始化app配置 ...
- oracle:SQL时间段
oracle: SQL时间段 CREATEDATE between to_date('" + startDate + " 00:00:00','yyyy-mm-dd hh24:mi ...
- 选择排序java实现
package text.algorithm; /** * 选择排序 * O(n^2);空间复杂度O(1); */public class SelectionSort { public static ...
- CCF CSP 201812-1 小明上学
题目链接:http://118.190.20.162/view.page?gpid=T80 问题描述 试题编号: 201812-1 试题名称: 小明上学 时间限制: 1.0s 内存限制: 512.0M ...
- centos7安装配置jdk
① java -version 可以查看系统自带的openjdk版本信息 ② rpm -qa | grep java 查看系统自带的Java文件 ③ 卸载文件(noarch文件可以不用删除) -- ...
- 解决 IntelliJ IDEA Tomcat 控制台中文输出乱码问题
解决办法 找到安装IDEA的bin目录将idea.exe.vmoptions和idea64.exe.vmoptions两个文件打开分别在文件最末尾添加-Dfile.encoding=UTF-8