问题描述
大家好,
很抱歉,如果我的标题不正确...我只想知道您将如何操作当前目录位置?这是场景:
假设我的项目位于c://myfiles/program/myproject
而我的exe文件位于
Hello guys,
I''m sorry if my title is not correct... I just want to know how will you be able to manipulate your current directory location? Here is the scenario:
Assuming that my project is located in c://myfiles/program/myproject
and my exe file is located in
c://myfiles/program/myproject/bin/debug/myexe.exe
所以我想做的就是获取现有的项目位置,它只是
So what I want to do is I want to get the existing project location which is only the
c://myfiles/program/myproject
而不是
c://myfiles/program/myproject/bin/debug
我使用此代码来获取当前项目位置
I used this code to get the current project location
string startupPath = System.IO.Directory.GetCurrentDirectory()
,但它仅返回此
but it only returns this
c://myfiles/program/myproject/bin/debug
我想备份2个目录,这样我可以转到
I want to back 2 directories that way I can go to
c://myfiles/program/myproject
...
我怎么做?
请帮忙.
在此先感谢
...
How do i do that?
Please help.
Thanks in advance
推荐答案
string exeDirectory =
System.IO.Path.GetDirectoryName(
System.Reflection.Assembly.GetEntryAssembly().Location);
如果找到当前正在运行的应用程序(.EXE文件)的入口程序集的位置,更确切地说,是其主要可执行模块的位置,则此方法也不依赖于运行此代码的程序集.
This method also does not depend on the assembly running this code, if finds location of the entry assembly of the currently running application (.EXE file), more exactly, location of its main executable module.
string startupPath = AppDomain.CurrentDomain.BaseDirectory.ToString()
问候,
代数
Regards,
Algem
这篇关于如何操作目录位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!