Path.GetInvalidPathChars Método
Definição
Obtém uma matriz que contém os caracteres que não são permitidos em nomes de caminho.Gets an array containing the characters that are not allowed in path names.
public:
static cli::array <char> ^ GetInvalidPathChars();
public static char[] GetInvalidPathChars ();
static member GetInvalidPathChars : unit -> char[]
Public Shared Function GetInvalidPathChars () As Char()
Retornos
- Char[]
Uma matriz que contém os caracteres que não são permitidos em nomes de caminho.An array containing the characters that are not allowed in path names.
Exemplos
O exemplo a seguir demonstra o GetInvalidFileNameChars método e o GetInvalidPathChars método para recuperar caracteres inválidos.The following example demonstrates the GetInvalidFileNameChars method and the GetInvalidPathChars method to retrieve invalid characters.
using namespace System;
using namespace System::IO;
namespace PathExample
{
public ref class GetCharExample
{
public:
static void Main()
{
// Get a list of invalid path characters.
array<Char>^ invalidPathChars = Path::GetInvalidPathChars();
Console::WriteLine("The following characters are invalid in a path:");
ShowChars(invalidPathChars);
Console::WriteLine();
// Get a list of invalid file characters.
array<Char>^ invalidFileChars = Path::GetInvalidFileNameChars();
Console::WriteLine("The following characters are invalid in a filename:");
ShowChars(invalidFileChars);
}
static void ShowChars(array<Char>^ charArray)
{
Console::WriteLine("Char\tHex Value");
// Display each invalid character to the console.
for each (Char someChar in charArray)
{
if (Char::IsWhiteSpace(someChar))
{
Console::WriteLine(",\t{0:X4}", (Int16)someChar);
}
else
{
Console::WriteLine("{0:c},\t{1:X4}", someChar, (Int16)someChar);
}
}
}
};
};
int main()
{
PathExample::GetCharExample::Main();
}
// Note: Some characters may not be displayable on the console.
// The output will look something like:
//
// The following characters are invalid in a path:
// Char Hex Value
// ", 0022
// <, 003C
// >, 003E
// |, 007C
// ...
//
// The following characters are invalid in a filename:
// Char Hex Value
// ", 0022
// <, 003C
// >, 003E
// |, 007C
// ...
using System;
using System.IO;
namespace PathExample
{
class GetCharExample
{
public static void Main()
{
// Get a list of invalid path characters.
char[] invalidPathChars = Path.GetInvalidPathChars();
Console.WriteLine("The following characters are invalid in a path:");
ShowChars(invalidPathChars);
Console.WriteLine();
// Get a list of invalid file characters.
char[] invalidFileChars = Path.GetInvalidFileNameChars();
Console.WriteLine("The following characters are invalid in a filename:");
ShowChars(invalidFileChars);
}
public static void ShowChars(char[] charArray)
{
Console.WriteLine("Char\tHex Value");
// Display each invalid character to the console.
foreach (char someChar in charArray)
{
if (Char.IsWhiteSpace(someChar))
{
Console.WriteLine(",\t{0:X4}", (int)someChar);
}
else
{
Console.WriteLine("{0:c},\t{1:X4}", someChar, (int)someChar);
}
}
}
}
}
// Note: Some characters may not be displayable on the console.
// The output will look something like:
//
// The following characters are invalid in a path:
// Char Hex Value
// ", 0022
// <, 003C
// >, 003E
// |, 007C
// ...
//
// The following characters are invalid in a filename:
// Char Hex Value
// ", 0022
// <, 003C
// >, 003E
// |, 007C
// ...
Imports System.IO
Namespace PathExample
Public Class GetCharExample
Public Shared Sub Main()
' Get a list of invalid path characters.
Dim invalidPathChars() As Char = Path.GetInvalidPathChars()
Console.WriteLine("The following characters are invalid in a path:")
ShowChars(invalidPathChars)
Console.WriteLine()
' Get a list of invalid file characters.
Dim invalidFileChars() As Char = Path.GetInvalidFileNameChars()
Console.WriteLine("The following characters are invalid in a filename:")
ShowChars(invalidFileChars)
End Sub
Public Shared Sub ShowChars(charArray As Char())
Console.WriteLine("Char" + vbTab + "Hex Value")
' Display each invalid character to the console.
For Each someChar As Char In charArray
If Char.IsWhiteSpace(someChar)
Console.WriteLine("," + vbTab + "{0:X4}", _
Microsoft.VisualBasic.Asc(someChar))
Else
Console.WriteLine("{0:c}," + vbTab +"{1:X4}", someChar, _
Microsoft.VisualBasic.Asc(someChar))
End If
Next someChar
End Sub
End Class
End Namespace
' Note: Some characters may not be displayable on the console.
' The output will look something like:
'
' The following characters are invalid in a path:
' Char Hex Value
' ", 0022
' <, 003C
' >, 003E
' |, 007C
' ...
'
' The following characters are invalid in a filename:
' Char Hex Value
' ", 0022
' <, 003C
' >, 003E
' |, 007C
' ...
Comentários
A matriz retornada por esse método não tem garantia de conter o conjunto completo de caracteres que são inválidos em nomes de arquivos e diretórios.The array returned from this method is not guaranteed to contain the complete set of characters that are invalid in file and directory names. O conjunto completo de caracteres inválidos pode variar de acordo com o sistema de arquivos.The full set of invalid characters can vary by file system. Por exemplo, em plataformas de área de trabalho baseadas no Windows, caracteres de caminho inválidos podem incluir caracteres ASCII/Unicode de 1 a 31, bem como pipe (|) e NULL (\ 0).For example, on Windows-based desktop platforms, invalid path characters might include ASCII/Unicode characters 1 through 31, as well as pipe (|) and null (\0).