다음을 통해 공유


PathFindNextComponentW 함수(shlwapi.h)

경로를 구문 분석하고 첫 번째 백슬래시 뒤에 있는 해당 경로의 부분을 반환합니다.

구문

LPCWSTR PathFindNextComponentW(
  [in] LPCWSTR pszPath
);

매개 변수

[in] pszPath

형식: PTSTR

구문 분석할 경로가 포함된 null로 끝나는 문자열에 대한 포인터입니다. 이 문자열은 MAX_PATH 문자와 종료 null 문자보다 길면 안 됩니다. 경로 구성 요소는 백슬라이시로 구분됩니다. instance 경우 경로 "c:\path1\path2\file.txt"에는 c:, path1, path2 및 file.txt 네 가지 구성 요소가 있습니다.

반환 값

형식: PTSTR

잘린 경로를 포함하는 null로 끝나는 문자열에 대한 포인터를 반환합니다.

pszPath가 경로의 마지막 구성 요소를 가리키는 경우 이 함수는 종료되는 null 문자에 대한 포인터를 반환합니다.

pszPath가 종료 null 문자를 가리키거나 호출이 실패하면 이 함수는 NULL을 반환합니다.

설명

PathFindNextComponent 는 백슬래시("\")가 발생할 때까지 경로 문자열을 걷고, 백슬래시를 포함하여 해당 지점까지의 모든 항목을 무시하고, 경로의 나머지 부분을 반환합니다. 따라서 경로가 백슬래시(예: \path1\path2)로 시작하는 경우 함수는 초기 백슬래시를 제거하고 나머지(path1\path2)를 반환합니다.

예제

다음 간단한 콘솔 애플리케이션은 다양한 문자열을 PathFindNextComponent 에 전달하여 함수가 경로 구성 요소로 인식하는 내용을 보여 주고 반환되는 내용을 표시합니다. Visual Studio에서 이 코드를 실행하려면 Shlwapi.lib에 연결하고 프로젝트 설정의 전처리기 명령에서 UNICODE를 정의해야 합니다.


#include <windows.h>
#include <iostream>
#include <shlwapi.h>

#pragma comment(lib, "shlwapi.lib")     // Link to this file.

int main()
{
    using namespace std;
   
    PCWSTR path = L"c:\\path1\\path2\\file.txt";
 
    // This loop passes a full path to PathFindNextComponent and feeds the 
    // results of that call back into the function until the entire path has
    // been walked.
    while (path)
    {
        PCWSTR oldPath = path;
        path = PathFindNextComponent(path);
 
        // The path variable pointed to the terminating null character.
        if (path == NULL)
        {
            wcout << L"The terminating null character returns NULL\n\n";
        }
        // The path variable pointed to a path with only one component.
		else if (*path == 0)
        {
            wcout << L"The path " << oldPath 
                  << L" returns a pointer to the terminating null character\n"; 
        }
        else 
        {
            wcout << L"The path " << oldPath << L" returns " << path << L"\n";
        }
    }
 
    // These calls demonstrate the results of different path forms.
    // Note that where those paths begin with backslashes, those
    // backslashes are merely stripped away and the entire path is returned.

    PCWSTR path1 = L"\\path1";

    wcout << L"The path " << path1 << L" returns " 
          << PathFindNextComponent(path1);
        
    PCWSTR path2 = L"\\path1\\path2";

    wcout << L"\nThe path " << path2 << L" returns "
          << PathFindNextComponent(path2);
        
    PCWSTR path3 = L"path1\\path2";
 
    wcout << L"\nThe path " << path3 << L" returns "
          << PathFindNextComponent(path3);
 
    wcout << L"\nThe path " << L"c:\\file.txt" << L" returns "
          << PathFindNextComponent(L"c:\\file.txt");
 
    return 0;
}

OUTPUT:
===========
The path c:\path1\path2\file.txt returns path1\path2\file.txt
The path path1\path2\file.txt returns path2\file.txt
The path path2\file.txt returns file.txt
The path file.txt returns a pointer to the terminating null character
The terminating null character returns NULL

The path \path1 returns path1
The path \path1\path2 returns path1\path2
The path path1\path2 returns path2
The path c:\file.txt returns file.txt

참고

shlwapi.h 헤더는 UNICODE 전처리기 상수의 정의에 따라 이 함수의 ANSI 또는 유니코드 버전을 자동으로 선택하는 별칭으로 PathFindNextComponent를 정의합니다. 인코딩 중립 별칭을 인코딩 중립이 아닌 코드와 혼합하면 컴파일 또는 런타임 오류가 발생하는 불일치가 발생할 수 있습니다. 자세한 내용은 함수 프로토타입에 대한 규칙을 참조하세요.

요구 사항

   
지원되는 최소 클라이언트 Windows 2000 Professional, Windows XP [데스크톱 앱만 해당]
지원되는 최소 서버 Windows 2000 Server[데스크톱 앱만]
대상 플랫폼 Windows
헤더 shlwapi.h
라이브러리 Shlwapi.lib
DLL Shlwapi.dll(버전 4.71 이상)