0

I'm trying to combine a path and a string to create a path, although the path is the string only? what I mean is, when I use Console.WriteLine(filepath) all that comes out is the string and not the path, and when I write the argument (whats used as the path, its a argument you set when you open the .exe) its comes out properly, as the set path, as the string:

string filepath = Path.Combine(arg1, @"\tf1.dat");

arg1 is the argument turned into a string.

user3026440
  • 85
  • 1
  • 5
  • Or actually [Why Does Path.Combine not properly concatenate filenames that start with Path.DirectorySeparatorChar](http://stackoverflow.com/questions/53102/why-does-path-combine-not-properly-concatenate-filenames-that-start-with-path-di), as that one is older. – CodeCaster Nov 27 '13 at 21:11

2 Answers2

4

You shouldn't have the \ at the start of the second argument. You want:

string filepath = Path.Combine(arg1, "tf1.dat");

Otherwise it thinks you want an absolute filename, basically.

Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331
Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
3

Try this:

string filepath = Path.Combine(arg1, "tf1.dat");

Remove the slash \ from your second argument of Path.Combine to avoid making it an absolute filename

Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331