如何获取命令提示符中的文件夹路径待命,而不是在C#控制台应用程序中?
我创建了一个C#控制台应用程序,以便在命令提示符中使用。
这是我的代码:
static void Main(string[] args)
{
string path = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
Console.WriteLine(path);
}
我想获得 c:\ users \ sophairk 而不是 c:\ testswc 。
如何修复我的代码以作为我想要的?
提前致谢!
I have created a C# Console App for use in Command Prompt.
Here is my code:
static void Main(string[] args)
{
string path = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
Console.WriteLine(path);
}
I want to get C:\Users\Sophairk instead of C:\testswc.
How to fix my code to get as what I want?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您调用
assembly.getEntryAssembly()。位置
时,它将返回执行.exe文件的路径。假设Sophairk是用户的用户名,那么您可以执行此操作:
如果是您想要的当前目录,则可以执行此操作,
您可以在此处查看文档:
https:/ com/en-us/dotnet/api/system.environment.specialfolder?view = net-6.0
查看还有哪些其他“特殊文件夹”。
When you call
Assembly.GetEntryAssembly().Location
then it will return the path of the executing .exe file.Assuming that Sophairk is the username of your user, then you can do this:
If it is the current directory that you want, then you can do this
You can check out the documentation here:
https://learn.microsoft.com/en-us/dotnet/api/system.environment.specialfolder?view=net-6.0
To see what other "Special Folders" are available.