다음을 통해 공유


PathFileExistsA 함수(shlwapi.h)

파일 또는 폴더와 같은 파일 시스템 개체의 경로가 유효한지 여부를 확인합니다.

구문

BOOL PathFileExistsA(
  [in] LPCSTR pszPath
);

매개 변수

[in] pszPath

형식: LPCTSTR

확인할 개체의 전체 경로를 포함하는 최대 길이 MAX_PATH null로 끝나는 문자열에 대한 포인터입니다.

반환 값

형식: BOOL

파일이 있으면 TRUE입니다. 그렇지 않으면 FALSE입니다. 확장된 오류 정보는 GetLastError 를 호출합니다.

설명

이 함수는 경로의 유효성을 테스트합니다.

UNC(범용 명명 규칙)로 지정된 경로는 파일로만 제한됩니다. 즉, \server\share\file이 허용됩니다. 서버 또는 서버 공유에 대한 UNC 경로는 허용되지 않습니다. 즉, \server 또는 \server\share입니다. 탑재된 원격 드라이브가 작동하지 않으면 이 함수는 FALSE 를 반환합니다.

예제


#include <windows.h>
#include <iostream.h>
#include "Shlwapi.h"

void main(void)
{
    // Valid file path name (file is there).
    char buffer_1[ ] = "C:\\TEST\\file.txt"; 
    char *lpStr1;
    lpStr1 = buffer_1;
    
    // Invalid file path name (file is not there).
    char buffer_2[ ] = "C:\\TEST\\file.doc"; 
    char *lpStr2;
    lpStr2 = buffer_2;
    
    // Return value from "PathFileExists".
    int retval;
    
    // Search for the presence of a file with a true result.
    retval = PathFileExists(lpStr1);
    if(retval == 1)
    {
        cout << "Search for the file path of : " << lpStr1 << endl;
        cout << "The file requested \"" << lpStr1 << "\" is a valid file" << endl;
        cout << "The return from function is : " << retval << endl;
    }
    
    else
    {
        cout << "\nThe file requested " << lpStr1 << " is not a valid file" << endl;
        cout << "The return from function is : " << retval << endl;
    }
    
    // Search for the presence of a file with a false result.
    retval = PathFileExists(lpStr2);
    
    if(retval == 1)
    {
        cout << "\nThe file requested " << lpStr2 << "is a valid file" << endl;
        cout << "Search for the file path of : " << lpStr2 << endl;
        cout << "The return from function is : " << retval << endl;
    }
    else
    {
        cout << "\nThe file requested \"" << lpStr2 << "\" is not a valid file" << endl;
        cout << "The return from function is : " << retval << endl;
    }
}

OUTPUT
==============
Search for the file path of : C:\TEST\file.txt
The file requested "C:\TEST\file.txt" is a valid file
The return from function is : 1

The file requested "C:\TEST\file.doc" is not a valid file
The return from function is : 0

참고

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

요구 사항

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