Monday, March 24, 2003 4:54 PM HomeSkillet

Path.Combine

I often see people using string concatenation to create directory names. Like this:

string path = "C:\\data\\" + filename; < /EM >

But there's a much better API:

string path = System.IO.Path.Combine("C:\\data", filename);< /EM >

Not only does this take care of the whole, "Do I need a trailing slash?" issue, but if you specify an absolute path for the second parameter, it will just return the second parameter. That means that someone can enter "foo" or "C:\\temp\\foo" for filename, and it'll do what you'd expect.

[CraigBlog]

This is a great little tid-bit... you gotta love this framework.. i have been working with it since beta one and I still learn something new everyday.

Filed under:

Comments

No Comments

Leave a Comment

(required) 
(required) 
(optional)
(required)