Path.GetFullPath 메서드

정의

오버로드

GetFullPath(String)

지정된 경로 문자열에 대한 절대 경로를 반환합니다.

GetFullPath(String, String)

상대 경로와 정규화된 기본 경로에서 절대 경로를 반환합니다.

GetFullPath(String)

Source:
Path.Unix.cs
Source:
Path.Unix.cs
Source:
Path.Unix.cs

지정된 경로 문자열에 대한 절대 경로를 반환합니다.

public:
 static System::String ^ GetFullPath(System::String ^ path);
public static string GetFullPath (string path);
static member GetFullPath : string -> string
Public Shared Function GetFullPath (path As String) As String

매개 변수

path
String

절대 경로 정보를 가져올 파일 또는 디렉터리입니다.

반환

"C:\MyFile.txt"처럼 path의 정규화된 위치입니다.

예외

path 는 길이가 0인 문자열이거나, Windows 시스템의 공백만 포함하거나, 에 GetInvalidPathChars()정의된 잘못된 문자 중 하나 이상을 포함합니다.

또는

절대 경로를 검색할 수 없는 경우

호출자에게 필요한 사용 권한이 없습니다.

path이(가) null인 경우

.NET Framework 전용: path 볼륨 식별자의 일부가 아닌 콜론(":")을 포함합니다(예: "c:\").

지정된 경로, 파일 이름 또는 둘 다가 시스템에서 정의한 최대 길이를 초과합니다.

예제

다음 예제에서는 Windows 기반 데스크톱 플랫폼의 GetFullPath 메서드를 보여 줍니다.

String^ fileName = "myfile.ext";
String^ path = "\\mydir\\";
String^ fullPath;
fullPath = Path::GetFullPath( path );
Console::WriteLine( "GetFullPath('{0}') returns '{1}'", path, fullPath );
fullPath = Path::GetFullPath( fileName );
Console::WriteLine( "GetFullPath('{0}') returns '{1}'", fileName, fullPath );

// Output is based on your current directory, except
// in the last case, where it is based on the root drive
// GetFullPath('mydir') returns 'C:\temp\Demo\mydir'
// GetFullPath('myfile.ext') returns 'C:\temp\Demo\myfile.ext'
// GetFullPath('\mydir') returns 'C:\mydir'
string fileName = "myfile.ext";
string path1 = @"mydir";
string path2 = @"\mydir";
string fullPath;

fullPath = Path.GetFullPath(path1);
Console.WriteLine("GetFullPath('{0}') returns '{1}'",
    path1, fullPath);

fullPath = Path.GetFullPath(fileName);
Console.WriteLine("GetFullPath('{0}') returns '{1}'",
    fileName, fullPath);

fullPath = Path.GetFullPath(path2);
Console.WriteLine("GetFullPath('{0}') returns '{1}'",
    path2, fullPath);

// Output is based on your current directory, except
// in the last case, where it is based on the root drive
// GetFullPath('mydir') returns 'C:\temp\Demo\mydir'
// GetFullPath('myfile.ext') returns 'C:\temp\Demo\myfile.ext'
// GetFullPath('\mydir') returns 'C:\mydir'
Dim fileName As string = "myfile.ext"
Dim path1 As string = "mydir"
Dim path2 As string = "\mydir"
Dim fullPath As string

fullPath = Path.GetFullPath(path1)
Console.WriteLine("GetFullPath('{0}') returns '{1}'", _
    path1, fullPath)

fullPath = Path.GetFullPath(fileName)
Console.WriteLine("GetFullPath('{0}') returns '{1}'", _
    fileName, fullPath)

fullPath = Path.GetFullPath(path2)
Console.WriteLine("GetFullPath('{0}') returns '{1}'", _
    path2, fullPath)

' Output is based on your current directory, except
' in the last case, where it is based on the root drive
' GetFullPath('mydir') returns 'C:\temp\Demo\mydir'
' GetFullPath('myfile.ext') returns 'C:\temp\Demo\myfile.ext'
' GetFullPath('\mydir') returns 'C:\mydir'

설명

절대 경로에는 시스템에서 파일 또는 디렉터리를 찾는 데 필요한 모든 정보가 포함됩니다.

에 지정된 path 파일 또는 디렉터리가 존재하지 않아도 됩니다. 예를 들어 c:\temp\newdir이 현재 디렉터리인 경우 test.txt 같은 파일 이름에서 를 호출 GetFullPath 하면 c:\temp\newdir\test.txt반환됩니다. 파일이 없습니다.

중요

가 상대 경로인 경우 path 이 오버로드는 현재 드라이브 및 현재 디렉터리를 기반으로 할 수 있는 정규화된 경로를 반환합니다. 애플리케이션이 실행되면 언제든지 현재 드라이브 및 현재 디렉터리가 변경됩니다. 따라서 이 오버로드에서 반환된 경로를 미리 확인할 수 없습니다. 결정적 경로를 반환하려면 오버로드를 호출합니다 GetFullPath(String, String) . 메서드를 호출하여 경로가 IsPathFullyQualified 정규화되었는지 상대 경로인지 여부와 에 대한 호출 GetFullPath 이 필요한지 여부를 확인할 수도 있습니다.

그러나 가 있는 경우 path 호출자는 에 대한 path경로 정보를 가져올 수 있는 권한이 있어야 합니다. 클래스의 대부분의 멤버와 Path 달리 이 메서드는 파일 시스템에 액세스합니다.

이 메서드는 현재 디렉터리와 현재 볼륨 정보를 사용하여 를 정규화 path합니다. 에서 pathGetFullPath 만 파일 이름을 지정하는 경우 현재 디렉터리의 정규화된 경로를 반환합니다.

짧은 파일 이름을 전달하면 긴 파일 이름으로 확장됩니다.

경로에 중요한 문자가 없으면 하나 이상의 "." 문자 뒤에 공백이 있는 경우가 아니면 유효하지 않습니다. 그러면 "." 또는 ".."로 구문 분석됩니다.

.NET Core 1.1 이상 버전 및 .NET Framework 4.6.2 이상 버전도 "\\\?\C:\"와 같은 디바이스 이름을 포함하는 경로를 지원합니다.

Windows의 파일 경로 형식에 대한 자세한 내용은 Windows 시스템의 파일 경로 형식을 참조하세요. 일반적인 I/O 작업 목록은 일반적인 I/O 작업을 참조하세요.

추가 정보

적용 대상

GetFullPath(String, String)

Source:
Path.Unix.cs
Source:
Path.Unix.cs
Source:
Path.Unix.cs

상대 경로와 정규화된 기본 경로에서 절대 경로를 반환합니다.

public:
 static System::String ^ GetFullPath(System::String ^ path, System::String ^ basePath);
public static string GetFullPath (string path, string basePath);
static member GetFullPath : string * string -> string
Public Shared Function GetFullPath (path As String, basePath As String) As String

매개 변수

path
String

basePath에 연결할 상대 경로입니다.

basePath
String

정규화된 경로의 시작입니다.

반환

절대 경로입니다.

예외

path 또는 basePathnull인 경우

basePath는 정규화된 경로가 아닙니다.

또는

path 또는 basePathGetInvalidPathChars()에 정의된 잘못된 문자가 하나 이상 포함되어 있는 경우

예제

다음 예제에서는 애플리케이션의 현재 디렉터리를 나타내는 변수 basePath를 정의합니다. 그런 다음 메서드에 GetFullPath 전달하여 애플리케이션의 데이터 디렉터리에 대한 정규화된 경로를 가져옵니다.

using System;
using System.IO;

class Program
{
    static void Main()
    {
        string basePath = Environment.CurrentDirectory;
        string relativePath = "./data/output.xml";
 
        // Unexpectedly change the current directory.
        Environment.CurrentDirectory = "C:/Users/Public/Documents/";
        
        string fullPath = Path.GetFullPath(relativePath, basePath);
        Console.WriteLine($"Current directory:\n   {Environment.CurrentDirectory}");
        Console.WriteLine($"Fully qualified path:\n   {fullPath}");
    }
}
// The example displays the following output:
//   Current directory:
//      C:\Users\Public\Documents
//   Fully qualified path:
//      C:\Utilities\data\output.xml
Imports System.IO

Module Program
    Public Sub Main()
        Dim basePath As String = Environment.CurrentDirectory
        Dim relativePath As String = "./data/output.xml"
 
        ' Unexpectedly change the current directory.
        Environment.CurrentDirectory = "C:/Users/Public/Documents/"
        
        Dim fullPath As String = Path.GetFullPath(relativePath, basePath)
        Console.WriteLine($"Current directory:\n   {Environment.CurrentDirectory}")
        Console.WriteLine($"Fully qualified path:\n   {fullPath}")
    End Sub
End Module
' The example displays the following output:
'   Current directory:
'      C:\Users\Public\Documents
'   Fully qualified path:
'      C:\Utilities\data\output.xml

설명

가 빈 경로이면 path 메서드는 를 반환합니다 basePath. 가 정규화된 경로이면 path 메서드가 메서드에 GetFullPath(String) 전달 path 되고 결과를 반환합니다.

상대 경로를 사용할 때 지정된 볼륨 및 루팅된 디렉터리에 따라 결정적 경로를 반환하려면 이 메서드를 사용합니다. 현재 드라이브 디렉터리를 기반으로 미리 정의된 basePath 가 아니라 를 사용하면 현재 드라이브 및 디렉터리의 예기치 않은 변경으로 인해 원치 않는 파일 경로가 보호됩니다.

적용 대상