假设我在系统C#
的目录中有一个已编译的example2.exe
程序(我们称之为$PATH
),因此我可以从Windows的任何文件夹中调用它。在命令行中,我进入c:\apps
并以现有文件作为参数运行example2.exe
,例如:example2.exe file.txt
。是否有可能获得file.txt
的完整路径?
另一个选项可能是..\file.txt
,它不会指向当前字典中的文件。
答案 0 :(得分:0)
Directory.GetCurrentDirectory正是您要找的。 p>
var fileName = "file.txt"; //comes from args obviously
var fullPath = Path.Combine(Directory.GetCurrentDirectory(), fileName);