-1

I'm trying to get the full path to a file.
I have the "end" of the path like:

\some_folder\myTextFile.txt

and the "beginning" like:

c:\Users\me\...

how do I find the absolute path to the textfile?

Axel_s
  • 21
  • 4
  • 3
    `System.IO.Path.Combine` – Dai Oct 10 '20 at 15:44
  • [How to convert a relative path to an absolute path in a Windows application?](https://stackoverflow.com/q/1399008/995714): [`Path.GetFullPath()`](https://learn.microsoft.com/en-us/dotnet/api/system.io.path.getfullpath?view=netcore-3.1) – phuclv Oct 10 '20 at 15:54

2 Answers2

2
using System.IO
(...)
string relativePath = "\some_folder\myTextFile.txt";
string absolutePath = Path.GetFullPath(relativePath);

should work

Casper Dijkstra
  • 1,615
  • 10
  • 37
0
 string [] fileEntries = Directory.GetFiles(targetDirectory);
foreach(string a in fileEntries)
{

    if(a.Contains("\some_folder\myTextFile.tx"))
   {
         return a
   }
  else
  {
     continue;
  }

}
user13573775
  • 19
  • 2
  • 7
  • While this code may solve the question, [including an explanation](https://meta.stackexchange.com/q/114762) of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please [edit] your answer to add explanations and give an indication of what limitations and assumptions apply. – fcdt Oct 10 '20 at 17:47