Path.GetInvalidPathChars 메서드

정의

경로 이름에 사용할 수 없는 문자가 포함된 배열을 가져옵니다.

public:
 static cli::array <char> ^ GetInvalidPathChars();
public static char[] GetInvalidPathChars ();
static member GetInvalidPathChars : unit -> char[]
Public Shared Function GetInvalidPathChars () As Char()

반환

Char[]

파일 이름에 사용할 수 없는 문자가 포함된 배열입니다.

예제

다음 예제에서는 잘못된 문자를 검색하는 메서드와 GetInvalidPathChars 메서드를 보여 GetInvalidFileNameChars 줍니다.

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
' ...

설명

이 메서드에서 반환된 배열은 파일 및 디렉터리 이름에 잘못된 전체 문자 집합을 포함하도록 보장되지 않습니다. 잘못된 문자의 전체 집합은 파일 시스템에 따라 달라질 수 있습니다. 예를 들어 Windows 기반 데스크톱 플랫폼에서 잘못된 경로 문자에는 파이프(|) 및 null(\0)뿐만 아니라 ASCII/유니코드 문자 1~31이 포함될 수 있습니다.

적용 대상