Funzione PathFileExistsW (shlwapi.h)

Determina se un percorso di un oggetto file system, ad esempio un file o una cartella, è valido.

Sintassi

BOOL PathFileExistsW(
  [in] LPCWSTR pszPath
);

Parametri

[in] pszPath

Tipo: LPCTSTR

Puntatore a una stringa con terminazione Null di lunghezza massima MAX_PATH contenente il percorso completo dell'oggetto da verificare.

Valore restituito

Tipo: BOOL

TRUE se il file esiste; in caso contrario, FALSE. Chiamare GetLastError per informazioni sugli errori estese. Se il file non esiste, GetLastError restituirà ERROR_FILE_NOT_FOUND.

Commenti

Questa funzione verifica la validità del percorso.

Un percorso specificato da Universal Naming Convention (UNC) è limitato solo a un file; vale a dire, \server\share\file è consentito. Non è consentito un percorso UNC a una condivisione server o server; ovvero \server o \server\share. Questa funzione restituisce FALSE se un'unità remota montata non è disponibile.

Esempi


#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

Nota

L'intestazione shlwapi.h definisce PathFileExists come alias che seleziona automaticamente la versione ANSI o Unicode di questa funzione in base alla definizione della costante del preprocessore UNICODE. La combinazione dell'utilizzo dell'alias indipendente dalla codifica con il codice che non è indipendente dalla codifica può causare mancate corrispondenze che generano errori di compilazione o di runtime. Per altre informazioni, vedere Convenzioni per i prototipi di funzioni.

Requisiti

Requisito Valore
Client minimo supportato Windows 2000 Professional, Windows XP [solo app desktop]
Server minimo supportato Windows 2000 Server [solo app desktop]
Piattaforma di destinazione Windows
Intestazione shlwapi.h
Libreria Shlwapi.lib
DLL Shlwapi.dll (versione 4.71 o successiva)