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#: 获取当前路径的更多相关文章

  1. [No00006F]总结C#获取当前路径的各种方法

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  2. C#获取当前路径的7种方法

    总结C#获取当前路径的7种方法 C#获取当前路径的方法如下: 1. System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName ...

  3. 【转】C#(ASP.Net)获取当前路径的方法集合

    转自:http://www.gaobo.info/read.php/660.htm //获取当前进程的完整路径,包含文件名(进程名). string str = this.GetType().Asse ...

  4. C\C++ 获取当前路径

    C\C++ 获取当前路径   获取当前工作目录是使用函数:getcwd.cwd指的是“current working directory”,这样就好记忆了. 函数说明: 函数原型:char* getc ...

  5. [转]Java获取当前路径

    1.利用System.getProperty()函数获取当前路径:System.out.println(System.getProperty("user.dir"));//user ...

  6. C#获取当前路径的方法

    C#获取当前路径的方法如下: 1. System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName -获取模块的完整路径. 2. ...

  7. 【转】java获取当前路径的几种方法

    1.利用System.getProperty()函数获取当前路径: System.out.println(System.getProperty("user.dir"));//use ...

  8. C#获取当前路径,获取当前路径的上一层路径

    C#获取当前路径的方法如下: (1)string path1 = System.Environment.CurrentDirectory; //C:\...\bin\Debug -获取和设置当前工作目 ...

  9. Java获取当前路径

    1.利用System.getProperty()函数获取当前路径:System.out.println(System.getProperty("user.dir"));//user ...

  10. C#获取当前路径的几种方法

    C#获取当前路径的方法如下: 1. System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName -获取模块的完整路径. 2. ...

随机推荐

  1. SDP协议中的Continuation State

    在SDP request和SDP response中,最后一部分为Continuation State,结构如下: 它用于一次response不够把所有的Data传回去的情况.这时候需要将respon ...

  2. BLE-NRF51822教程18-overview

    转自:http://blog.csdn.NET/xgbing 蓝牙协议栈 nrf51822开发中,蓝牙协议栈和应用开发是分开的. (1)兼容蓝牙4.0低功耗协议栈基带层,L2CAP\AAT\SM\GA ...

  3. C++ 简单 Hash容器的实现

    主要实现了以整数为关键字的hash,以key%m_nSize为哈希函数,以(hash(key)+i)%m_nSize重新寻址,并附带了elf_hash的实现,使用过程中可灵活修改. #ifndef _ ...

  4. 【python】RGB图片到灰度图的转换

    在做立体匹配求深度图的时候遇到这个问题,用惯了matlab的rgb2gray,倒是不熟悉python的实现,在网上找到了相关方案,记下来已作备用 RGB到灰度图转换公式: Y' = 0.299 R + ...

  5. Selenium2学习-034-WebUI自动化实战实例-032-获取页面 body 大小

    获取 body 元素大小的方法,非常简单,直接上码,敬请参阅! /** * Get body size * * @author Aaron.ffp * @version V1.0.0: autoSel ...

  6. js方法参数默认值设置

    这里的默认值设置 很容易以为和php相似 function(v1,v2="test") { alert(v2); } 但这样是不对的,js方法,如需传参,甚至可以不用预定义(也就是 ...

  7. [收藏夹整理]OpenCV部分

    OpenCV中文论坛 OpenCV论坛 opencv视频教程目录(初级) OpenCV 教程 Opencv感想和一些分享 tornadomeet 超牛的大神 [数字图像处理]C++读取.旋转和保存bm ...

  8. POJ 1528问题描述

    Description From the article Number Theory in the 1994 Microsoft Encarta: ``If a, b, c are integers ...

  9. error LNK2005 int __cdecl 解决方案【转】

    error LNK2005: "int __cdecl isPtInPolygon(class std::vector<struct double2,class std::alloca ...

  10. Java文件操作①——XML文件的读取

    一.邂逅XML 文件种类是丰富多彩的,XML作为众多文件类型的一种,经常被用于数据存储和传输.所以XML在现今应用程序中是非常流行的.本文主要讲Java解析和生成XML.用于不同平台.不同设备间的数据 ...