获取文本文件或 C# 中的任何文件的完整路径
尊敬的先生,
我的问题是,当我打开 txt 文件(即 abc.txt)时,我想获得仅在计算机中运行或打开文件的完整路径,我已经这样做了,
Process prs=Process.GetProcessByName("notepad");
foreach(Process p in prs)
{
p.Modules[0].FileName.ToString();
}
这给了我 Notepad.exe 路径。我想要我的文本文件路径如 D:\abc.txt 所以我可以得到这个。
谢谢
Respected Sir,
my Question is that when I am Opening my txt file i.e abc.txt so I want to get full path of only running or opening file in my computer I have done this
Process prs=Process.GetProcessByName("notepad");
foreach(Process p in prs)
{
p.Modules[0].FileName.ToString();
}
Which is giving me Notepad.exe path. I want my text file path like D:\abc.txt
so i can get this.
Thank You
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以附加FileSystemEventHandler并检查哪些文件被打开或更改。
也许这会有所帮助
http://www.codeguru.com/csharp/ csharp/cs_network/article.php/c6043
You could attach FileSystemEventHandler and check which files are opened, or changed.
Maybe this will help
http://www.codeguru.com/csharp/csharp/cs_network/article.php/c6043
对于记事本,您可以像这样获取文件名:
重要的部分是:
不幸的是,这不会为您提供完整路径。
For notepad, you can get the name of the file like this:
The important part being:
Unfortunately this won't get you the full path.