Export (0) Print
Expand All

Path.DirectorySeparatorChar Field

Provides a platform-specific character used to separate directory levels in a path string that reflects a hierarchical file system organization.

[Visual Basic]
Public Shared ReadOnly DirectorySeparatorChar As Char
[C#]
public static readonly char DirectorySeparatorChar;
[C++]
public: static __wchar_t DirectorySeparatorChar;
[JScript]
public static var DirectorySeparatorChar : Char;

Remarks

The character stored in this field cannot be in InvalidPathChars. AltDirectorySeparatorChar and DirectorySeparatorChar are both valid for separating directory levels in a path string.

The value of this field is a slash ("/") on Unix, and a backslash ("\") on the Windows and Macintosh operating systems.

Example

[Visual Basic, C#, C++] The following example demonstrates the use of the DirectorySeparatorChar field.

[Visual Basic] 
Console.WriteLine("Path.AltDirectorySeparatorChar={0}", Path.AltDirectorySeparatorChar)
Console.WriteLine("Path.DirectorySeparatorChar={0}", Path.DirectorySeparatorChar)
Console.WriteLine("Path.PathSeparator={0}", Path.PathSeparator)
Console.WriteLine("Path.VolumeSeparatorChar={0}", Path.VolumeSeparatorChar)

Console.Write("Path.InvalidPathChars=")
Dim c As Char
For Each c In Path.InvalidPathChars
    Console.Write(c)
Next c
Console.WriteLine()

[C#] 
Console.WriteLine("Path.AltDirectorySeparatorChar={0}", 
    Path.AltDirectorySeparatorChar);
Console.WriteLine("Path.DirectorySeparatorChar={0}", 
    Path.DirectorySeparatorChar);
Console.WriteLine("Path.PathSeparator={0}", 
    Path.PathSeparator);
Console.WriteLine("Path.VolumeSeparatorChar={0}", 
    Path.VolumeSeparatorChar);

Console.Write("Path.InvalidPathChars=");
foreach (char c in Path.InvalidPathChars)
    Console.Write(c);
Console.WriteLine();

[C++] 
Console::WriteLine(S"Path::AltDirectorySeparatorChar={0}", 
   (Path::AltDirectorySeparatorChar).ToString());
Console::WriteLine(S"Path::DirectorySeparatorChar={0}", 
   (Path::DirectorySeparatorChar).ToString());
Console::WriteLine(S"Path::PathSeparator={0}", 
   (Path::PathSeparator).ToString());
Console::WriteLine(S"Path::VolumeSeparatorChar={0}", 
   (Path::VolumeSeparatorChar).ToString());

Console::Write(S"Path::InvalidPathChars=");
for (int i = 0; i < Path::InvalidPathChars->Length; i++)
   Console::Write( Path::InvalidPathChars[i]);
Console::WriteLine();

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

Path Class | Path Members | System.IO Namespace | Working with I/O | Reading Text from a File | Writing Text to a File

Show:
© 2014 Microsoft