.NET: C#: 获取当前路径
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.Xml;
using System.Configuration;
using System.Reflection;
using System.Windows.Forms;
using System.IO;
namespace ConsoleTest
{
public class Program
{
static void Main(string[] args)
{
;
Console.WriteLine(Assembly.GetExecutingAssembly().Location);
Console.WriteLine(a.GetType().Assembly.Location);
Console.WriteLine(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
Console.WriteLine(System.Environment.CurrentDirectory);
Console.WriteLine(System.AppDomain.CurrentDomain.BaseDirectory);
Console.WriteLine(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase);
Console.WriteLine(System.Windows.Forms.Application.StartupPath);
Console.WriteLine(System.Windows.Forms.Application.ExecutablePath);
Console.WriteLine(System.IO.Directory.GetCurrentDirectory());
Console.WriteLine();
string path = "d:asdfasdf.bmp";
Console.WriteLine(Path.GetFileName(path));
Console.WriteLine(Path.GetExtension(path));
path = @"C:\Users\Administrator\Desktop\Demo";
if (Directory.Exists(path))
Console.WriteLine("{0} Directory exists", path);
else
Console.WriteLine("{0} Directory does not exist", path);
if (File.Exists(path))
Console.WriteLine("{0} File exists", path);
else
Console.WriteLine("{0} File does not exist", path);
path = @"C:\Users\Administrator\Desktop\Demo\Book.XML";
if (Directory.Exists(path))
Console.WriteLine("{0} Directory exists", path);
else
Console.WriteLine("{0} Directory does not exist", path);
if (File.Exists(path))
Console.WriteLine("{0} File exists", path);
else
Console.WriteLine("{0} File does not exist", path);
Console.WriteLine();
Console.WriteLine(Path.GetDirectoryName(path));
Console.WriteLine(Path.GetExtension(path));
Console.WriteLine(Path.GetFileName(path));
Console.WriteLine(Path.GetFileNameWithoutExtension(path));
Console.WriteLine(Path.GetPathRoot(path));
Console.WriteLine(Environment.SystemDirectory);
}
}
}
result

we usually use codes as below to get current directory:
System.Environment.CurrentDirectory
System.Windows.Forms.Application.StartupPath(using System.Windows.Forms;)
System.IO.Directory.GetCurrentDirectory() (using System.IO;)
I prefer: Enviroment.CurrentDirectory
.NET: C#: 获取当前路径的更多相关文章
- [No00006F]总结C#获取当前路径的各种方法
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- C#获取当前路径的7种方法
总结C#获取当前路径的7种方法 C#获取当前路径的方法如下: 1. System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName ...
- 【转】C#(ASP.Net)获取当前路径的方法集合
转自:http://www.gaobo.info/read.php/660.htm //获取当前进程的完整路径,包含文件名(进程名). string str = this.GetType().Asse ...
- C\C++ 获取当前路径
C\C++ 获取当前路径 获取当前工作目录是使用函数:getcwd.cwd指的是“current working directory”,这样就好记忆了. 函数说明: 函数原型:char* getc ...
- [转]Java获取当前路径
1.利用System.getProperty()函数获取当前路径:System.out.println(System.getProperty("user.dir"));//user ...
- C#获取当前路径的方法
C#获取当前路径的方法如下: 1. System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName -获取模块的完整路径. 2. ...
- 【转】java获取当前路径的几种方法
1.利用System.getProperty()函数获取当前路径: System.out.println(System.getProperty("user.dir"));//use ...
- C#获取当前路径,获取当前路径的上一层路径
C#获取当前路径的方法如下: (1)string path1 = System.Environment.CurrentDirectory; //C:\...\bin\Debug -获取和设置当前工作目 ...
- Java获取当前路径
1.利用System.getProperty()函数获取当前路径:System.out.println(System.getProperty("user.dir"));//user ...
- C#获取当前路径的几种方法
C#获取当前路径的方法如下: 1. System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName -获取模块的完整路径. 2. ...
随机推荐
- 【转】Laravel+Angularjs+D3打造可视化数据,RESTful+Ajax
http://897371388.iteye.com/blog/1975351 大致思路也就是下面,由于最近在学Laravel也在学Angularjs,加上之前做的项目用到了d3. 原来的方案如下: ...
- Python中dict的特点、更新dict、遍历dict
dict的第一个特点是查找速度快,无论dict有10个元素还是10万个元素,查找速度都一样.而list的查找速度随着元素增加而逐渐下降. 不过dict的查找速度快不是没有代价的,dict的缺点是占用内 ...
- 蓝牙Host Controller Interface笔记
1.概述 HCI提供了一个统一的使用蓝牙控制器(BR/EDR Controller,BR/EDR/LE Controller,LE Controller,AMP Controller等)的方法 ...
- SVN提交注意点
一.提交之前先更新 1. SVN更新的原则是要随时更新,随时提交.当完成了一个小功能,能够通过编译并且自己测试之后,谨慎地提交. 2. 如果在修改的期间别人也更改了sv ...
- Java实验报告五:Java网络编程及安全
Java实验报告五:Java网络编程及安全 ...
- Python 与 meta programming
meta programming: 编写能改变语言语法特性或者运行时特性的程序 Meta- 这个前缀在希腊语中的本意是「在…后,越过…的」,类似于拉丁语的 post-,比如 metaphysics 就 ...
- ArcGIS三大文件格式解析
原文:ArcGIS三大文件格式解析 Shape数据 Shapefile是ArcView GIS 3.x的原生数据格式,属于简单要素类,用点.线.多边形存储要素的形状,却不能存储拓扑关系,具有简单.快速 ...
- 【转】TableLayout(表格布局)
转自:http://www.cnblogs.com/zhangs1986/archive/2013/01/17/2864536.html TableLayout(表格布局) 表格布局模型以行列的形式管 ...
- miaov- 自动生成正V反V大于号V小于号V楼梯等图案
1. 核心:控制 数量的长度-1-i的位置,是放在left上还是top上?是放在前面还是后面! <!DOCTYPE html> <html lang="en"&g ...
- 记录:在老XPS1330上安装CentOS7
下图是设置时的图片,注意分区设置. 下图是安装成功的画面. 下图是在Gnome桌面环境打开Firefox上本博客的画面. 注意点: 1.安装时没啥特殊的,就两点,一是要分区设置好,图省事就让自动分区: ...