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. filter:Alpha总结

    filter:Alpha(Opacity=?, FinishOpacity=?, Style=?, StartX=?, StartY=?, FinishX=?, FinishY=?)Opacity:透 ...

  2. MyEclipse8.5 以debug模式启动tomcat6.0服务器 报错cannot connect to vm。

    打开MyEclipse8.5 想以debug模式启动tomcat6.0服务器,报  a configuration error occurred during startup.please verif ...

  3. Liunx 下使用cmake

    参考 http://blog.chinaunix.net/uid-28458801-id-3501768.html http://www.ibm.com/developerworks/cn/linux ...

  4. http协议(转)

    主要还是为了存放状态码··· 剖析 HTTP 协议   目录 HTTP 概述 HTTP 消息结构 HTTP 请求 HTTP 响应 HTTP 状态码 参考 回到顶部 HTTP 概述 HTTP 是什么? ...

  5. Docker Device Mapper 使用 direct-lvm

      一.Device Mapper: loop-lvm 默认 CentOS7 下 Docker 使用的 Device Mapper 设备默认使用 loopback 设备,后端为自动生成的稀疏文件,如下 ...

  6. 在大数据中,关于native包的编译步骤

    一.问题的由来: 二.解决问题的方法(所有的操作在root下完成): 1.前期需要的环境,下面的已经在伪分布式中配置好,不再重复 配置好jdk 配置好hadoop 2.上传还需要包 apache-ma ...

  7. 窗口类型(Widget, Window, Dialog, Desktop, SubWindow等等)

    http://doc.qt.io/qt-5/qwidget.html#windowFlags-prop http://doc.qt.io/qt-5/qtwidgets-widgets-windowfl ...

  8. Android OpenGL ES 开发教程 从入门到精通

    感谢,摘自:http://blog.csdn.net/mapdigit/article/details/7526556 Android OpenGL ES 简明开发教程 Android OpenGL ...

  9. spring3 mvc:方法返回值的学习

    新建后台代码用以测试返回类型,在这里我新建的如下: /** * 项目名称:Spring3mvc demo * Copyright ? 2010-2012 spartacus.org.cn All Ri ...

  10. magento多语言中文语言包

    语言包key:http://connect20.magentocommerce.com/community/Mage_Locale_zh_CN