How to get full file path from file name?

后端 未结 9 1817
[愿得一人]
[愿得一人] 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

    Try

    string fileName = "test.txt";
    FileInfo f = new FileInfo(fileName);
    string fullname = f.FullName;
    
    0 讨论(0)
  • 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)
    
    0 讨论(0)
  • 2021-02-08 17:43

    You Can use:

    string path = Path.GetFullPath(FileName);
    

    it will return the Full path of that mentioned file.

    0 讨论(0)
  • 2021-02-08 17:46
    private const string BulkSetPriceFile = "test.txt";
    ...
    var fullname = Path.GetFullPath(BulkSetPriceFile);
    
    0 讨论(0)
  • 2021-02-08 17:52

    I know my answer it's too late, but it might helpful to other's
    Try,

    Void Main()
    {
    string filename = @"test.txt";
    string filePath= AppDomain.CurrentDomain.BaseDirectory + filename ;
    Console.WriteLine(filePath);
    }
    
    0 讨论(0)
  • 2021-02-08 17:57

    Use Path.GetFullPath():

    http://msdn.microsoft.com/en-us/library/system.io.path.getfullpath.aspx

    This should return the full path information.

    0 讨论(0)
提交回复
热议问题