PathFileExists

strin tain tion

PathFileExists功能
Determines whether a path to a file system object such as a file or directory is valid.確定一個檔案或目錄的檔案系統對象的路徑是否是有效的。Syntax語法

BOOL PathFileExists ( __in LPCTSTR pszPath );
Parameters參數
pszPath[in] 類型:LPCTSTR
A pointer to a null-terminated string of maximum length max_path that contains the full path of the object to verify. 最大長度為MAX_PATH的不含'\0'的字元串指針,包含要驗證的完整路徑。

Return Value返回值

類型:BOOL
Returns TRUEif the file exists, or FALSEotherwise.如果該檔案存在返回TRUE,否則返回false

Remarks備註

This function tests the validity of the path.這個函式測試路徑的有效性。
A path specified by Universal Naming Convention (UNC) is limited to a file only; that is, \\server\share\file is permitted.由通用命名約定(UNC)指定的路徑是僅限於檔案只,也就是說,\ \伺服器\共享\檔案是允許的。 A UNC path to a server or server share is not permitted; that is, \\ serveror \\ server\ share.一個UNC路逕到伺服器或伺服器共享是不允許的,也就是說,\ \ 伺服器或\ \ 伺服器\ 共享。 This function returns FALSEif a mounted remote drive is out of service.該函式返回FALSE,如果安裝遠程驅動器是出於服務。

Examples舉例

Copy複製
#include <iostream.h>
#include "Shlwapi.h"
#pragma comment(lib,"Shlwapi.lib") /*需要加上此行才可以正確link,VC6.0*/
void main(void)
{
char buffer_1&#91; &#93; = "C:\\TEST\\file.txt"; //有效的檔案路徑名(檔案存在)
char *lpStr1;
lpStr1 = buffer_1;
char buffer_2&#91; &#93; = "C:\\TEST\\file.doc";// 無效的檔案路徑名(檔案不存在)
char *lpStr2;
lpStr2 = buffer_2;
int retval; //從“PathFileExists”返回值。
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;
}
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

Requirements要求
Minimum supported client最低支持的客戶端 Windows 2000 Professional, Windows XP的Windows 2000專業版,Windows XP
Minimum supported server最低支持的伺服器 Windows 2000 Server Windows 2000伺服器
Header頭 Shlwapi.h Shlwapi.h
Library圖書館 Shlwapi.lib Shlwapi.lib
DLL DLL shlwapi.dll (version 4.71 or later) SHLWAPI.DLL(版本4.71或更高版本)
Unicode and ANSI names Unicode和ANSI名稱 PathFileExistsW(Unicode) and PathFileExistsA(ANSI) PathFileExistsW(Unicode)PathFileExistsA(ANSI)

相關詞條

相關搜尋

熱門詞條

聯絡我們