开发者

full path of a folder in c#

i need to get the full folder path in a windows project using c#.I tried with path.getFulPath(file开发者_Go百科name).bt it returns the application path+filename.how can i get the actual path like "D:\eclipse_files\ads_data"?


A relative path such as myfile.txt is always resolved in relation to the current working directory.

In your case the current working directory seems to be D:\eclipse_files\ads_data so your relative file path gets resolved to D:\eclipse_files\ads_data\myfile.txt when you call Path.GetFullPath.

To solve the problem, either make sure that you start with an absolute path from the beginning, or, that your working directory is set correctly.

You can get/set the working directory using the Directory.GetCurrentDirectory and Directory.SetCurrentDirectory methods.


Your question is not very clear, but I think you're looking for this:

string path = Path.GetDirectoryName(filename);


If I have understood correctly, you have a filename, for example 'doc.txt', and you want to have a method to return the full path of this file regardless of where the application runs from?

If this is what you ask it is not possible. Have you considered that there might be several files called 'doc.txt' on your harddrives?

The best you can hope to do it to search all harddrives, and return a list of all files found with the same name, but that will just be ridicously slow.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜