How to get full file path from file name?

后端 未结 9 1985
[愿得一人]
[愿得一人] 2021-02-08 16:59

How do I get the full path for a given file?

e.g. I provide:

string filename = @\"test.txt\";

Result should be:

Full Fi         


        
9条回答
  •  我在风中等你
    2021-02-08 17:39

    Directory.GetCurrentDirectory

    string dirpath = Directory.GetCurrentDirectory();
    

    Prepend this dirpath to the filename to get the complete path.

    As @Dan Puzey indicated in the comments, it would be better to use Path.Combine

    Path.Combine(Directory.GetCurrentDirectory(), filename)
    

提交回复
热议问题