如何从文件名获取完整的文件路径 [英] How to get full file path from file name

查看:97
本文介绍了如何从文件名获取完整的文件路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,有人可以提供有关如何从文件名获取完整文件路径吗?"的正确答案.
例如:我提供:字符串文件名= @"test.txt";
我需要:完整文件路径= C:\ Windows \ ABC \ Test \ test.txt

解决方案

尝试以下操作:

 字符串 full = System.IO.File.Directory.GetCurrentDirectory()+ "  \\" +   test.txt"; 


希望对您有所帮助.


使用

 System.IO.Path.GetFullPath(filename); 

从文件名获取完整的文件路径.

从那开始,除非文件存在于当前工作目录中,否则您无法从文件名获取完整路径.在这种情况下,您可以使用Assembly.GetExecutingAssembly().Location.


Hi can anybody please provide proper answer for "How to get full file path from file name?"
Ex: I provide: string filename = @"test.txt";
I Required: Full File Path = C:\Windows\ABC\Test\test.txt

解决方案

Try this:

string full = System.IO.File.Directory.GetCurrentDirectory() + "\\" + "test.txt";


Hope this helps.


Use

System.IO.Path.GetFullPath(filename);

to get full file path from file name .


From that, you can''t get the full path from the filename, unless the file is present in your current working directory. If this is the case, you can use Assembly.GetExecutingAssembly().Location.


这篇关于如何从文件名获取完整的文件路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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