Função PathFileExistsW (shlwapi.h)
Determina se um caminho para um objeto do sistema de arquivos, como um arquivo ou pasta, é válido.
Sintaxe
BOOL PathFileExistsW(
[in] LPCWSTR pszPath
);
Parâmetros
[in] pszPath
Tipo: LPCTSTR
Um ponteiro para uma cadeia de caracteres terminada em nulo de comprimento máximo MAX_PATH que contém o caminho completo do objeto a ser verificado.
Retornar valor
Tipo: BOOL
TRUE se o arquivo existir; caso contrário, FALSE. Chame GetLastError para obter informações de erro estendidas. Se o arquivo não existir, GetLastError retornará ERROR_FILE_NOT_FOUND.
Comentários
Essa função testa a validade do caminho.
Um caminho especificado pela UNC (Convenção Universal de Nomenclatura) é limitado apenas a um arquivo; ou seja, \server\share\file é permitido. Um caminho UNC para um compartilhamento de servidor ou servidor não é permitido; ou seja, \server ou \server\share. Essa função retornará FALSE se uma unidade remota montada estiver fora de serviço.
Exemplos
#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
Observação
O cabeçalho shlwapi.h define PathFileExists como um alias que seleciona automaticamente a versão ANSI ou Unicode dessa função com base na definição da constante de pré-processador UNICODE. Misturar o uso do alias neutro de codificação com código que não seja neutro em codificação pode levar a incompatibilidades que resultam em erros de compilação ou de runtime. Para obter mais informações, consulte Convenções para protótipos de função.
Requisitos
Requisito | Valor |
---|---|
Cliente mínimo com suporte | Windows 2000 Professional, Windows XP [somente aplicativos da área de trabalho] |
Servidor mínimo com suporte | Windows 2000 Server [somente aplicativos da área de trabalho] |
Plataforma de Destino | Windows |
Cabeçalho | shlwapi.h |
Biblioteca | Shlwapi.lib |
DLL | Shlwapi.dll (versão 4.71 ou posterior) |