PathFileExists

PathFileExists是計算機函式。

基本介紹

  • 中文名:PathFileExists
  •  類型::LPCTSTR
  • 功能:路徑是否是有效的。
  • 對象:檔案或目錄的檔案系統對象的路徑
功能,語法,返回值,備註,舉例,最低要求,

功能

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[ ] = "C:\\TEST\\file.txt"; //有效的檔案路徑名(檔案存在)
char *lpStr1;
lpStr1 = buffer_1;
char buffer_2[ ] = "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

最低要求

客戶端最低要求
Windows 2000 Professional, Windows XP的Windows 2000專業版,Windows XP
伺服器最低要求
Windows 2000 Server Windows 2000伺服器
頭檔案
Shlwapi.h Shlwapi.h
lib程式庫
Shlwapi.lib Shlwapi.lib
DLL動態庫(不需要)
Shlwapi.dll (version 4.71 or later) SHLWAPI.DLL(版本4.71或更高版本)
有 Unicode 和 ANSI 兩種編碼
PathFileExistsW(Unicode) and PathFileExistsA(ANSI) PathFileExistsW(Unicode)PathFileExistsA(ANSI)

相關詞條

熱門詞條

聯絡我們