Path Class

Overview

  • Provides helper methods for working with file system paths as strings.

Examples

Change Extensions

// This does NOT rename the file! It is only a string operation.
Console.WriteLine(Path.ChangeExtension(@"C:\Public\Test.txt", ".doc"));

Combine Paths

string root = @"C:\Public\Test";
string subdir = @"Subtest\";
string combined = Path.Combine(root, subdir);
Console.WriteLine(combined);
 
// If there is no trailing slash at Subtest\ this would give
// C:\Public\Test instead of C:\Public\Test\Subtest
Console.WriteLine(Path.GetDirectoryName(combined));

Create Random Files

Console.WriteLine(Path.ChangeExtension(Path.GetRandomFileName(), ".txt"));
 
learning/exam70-536/path.txt · Last modified: 2008/08/27 11:28 by david
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki