Rob Chartier ~ Contemplation...

.NET, C#, Work, etc.

This is a Flickr badge showing public photos from Rob & Kat Chartier. Make your own badge here.

Even Quicker Links

System.IO.Path. Its there, so use it!

It seems to me that one of the most underused, but very useful classes is the System.IO.Path class. It has a bunch of static methods which are extremely valueable when dealing with file system paths.  Use it instead of doing some string parsing hack jobs!


Here is a list of methods:


ChangeExtension : Changes the extension of a path string.

***Combine : Combines two path strings.

***GetDirectoryName : Returns the directory information for the specified path string.

GetExtension : Returns the extension of the specified path string.

***GetFileName : Returns the file name and extension of the specified path string.

GetFileNameWithoutExtension : Returns the file name of the specified path string without the extension.

GetFullPath : Returns the absolute path for the specified path string.

GetPathRoot : Gets the root directory information of the specified path.

***GetTempFileName : Returns a uniquely named zero-byte temporary file on disk and returns the full path to that file.

GetTempPath : Returns the path of the current system's temporary folder.

HasExtension : Determines whether a path includes a file name extension.

IsPathRooted : Gets a value indicating whether the specified path string contains absolute or relative path information.


More information here:



Eric Newton said:

Good call, we all need to remind each other to not reinvent the wheel. In this case path parsing logic via System.IO.Path... Kudos!
# January 26, 2006 3:25 PM

Adam said:

I can't even begin to say how many times I've removed multiple line path parsing code from applications others have written and replaced it with one call to a method on the Path class.
# January 26, 2006 4:48 PM