Share via


Función PathFileExistsA (shlwapi.h)

Determina si una ruta de acceso a un objeto del sistema de archivos, como un archivo o una carpeta, es válida.

Sintaxis

BOOL PathFileExistsA(
  [in] LPCSTR pszPath
);

Parámetros

[in] pszPath

Tipo: LPCTSTR

Puntero a una cadena terminada en null de longitud máxima MAX_PATH que contiene la ruta de acceso completa del objeto que se va a comprobar.

Valor devuelto

Tipo: BOOL

TRUE si el archivo existe; de lo contrario, FALSE. Llame a GetLastError para obtener información de error extendida.

Comentarios

Esta función prueba la validez de la ruta de acceso.

Una ruta de acceso especificada por la Convención de nomenclatura universal (UNC) se limita únicamente a un archivo; es decir, se permite \server\share\file. No se permite una ruta unc a un servidor o recurso compartido de servidor; es decir, \server o \server\share. Esta función devuelve FALSE si una unidad remota montada está fuera del servicio.

Ejemplos


#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:

El encabezado shlwapi.h define PathFileExists como alias que selecciona automáticamente la versión ANSI o Unicode de esta función en función de la definición de la constante de preprocesador UNICODE. La combinación del uso del alias neutral de codificación con código que no es neutral de codificación puede dar lugar a errores de coincidencia que dan lugar a errores de compilación o tiempo de ejecución. Para obtener más información, vea Convenciones para prototipos de función.

Requisitos

   
Cliente mínimo compatible Windows 2000 Professional, Windows XP [solo aplicaciones de escritorio]
Servidor mínimo compatible Windows 2000 Server [solo aplicaciones de escritorio]
Plataforma de destino Windows
Encabezado shlwapi.h
Library Shlwapi.lib
Archivo DLL Shlwapi.dll (versión 4.71 o posterior)