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.
1 Comment
Comments have been disabled for this content.
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!