获取目录下执行code位于 [英] Get directory where executed code is located

查看:91
本文介绍了获取目录下执行code位于的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道,在我的code正在执行一些文件所在的同一目录中。我需要找到他们,并传递给另一种方法:

I know that in the same directory where my code is being executed some files are located. I need to find them and pass to another method:

MyLib.dll
Target1.dll
Target2.dll

Foo(new[] { "..\\..\\Target1.dll", "..\\..\\Target2.dll" });

于是我打电话 System.IO.Directory.GetFiles(路径,* .dll文件)。但现在我需要知道路径:

So I call System.IO.Directory.GetFiles(path, "*.dll"). But now I need to get know the path:

string path = new FileInfo((Assembly.GetExecutingAssembly().Location)).Directory.FullName)

但有更短的路?

but is there more short way?

推荐答案

您可以尝试的<一个href="http://msdn.microsoft.com/en-us/library/system.environment.currentdirectory.aspx"><$c$c>Environment.CurrentDirectory属性。请注意,根据应用程序的类型(控制台,的WinForms,ASP.NET,Windows服务,...)和它的方式运行,这可能表现不同。

You may try the Environment.CurrentDirectory property. Note that depending on the type of application (Console, WinForms, ASP.NET, Windows Service, ...) and the way it is run this might behave differently.

这篇关于获取目录下执行code位于的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆