共用方式為


PathIsRootW 函式 (shlwapi.h)

判斷路徑字串是否參考磁碟區的根目錄。

語法

BOOL PathIsRootW(
  [in] LPCWSTR pszPath
);

參數

[in] pszPath

類型: LPCTSTR

包含要驗證之路徑的 null 終止字串指標,其長度上限為 MAX_PATH。

傳回值

類型: BOOL

如果指定的路徑是根目錄,則傳回 TRUE ,否則傳回 FALSE

備註

針對 “”、“X:” 或 “\\server\share” 等路徑傳回 TRUE。 “.. 之類的路徑。\path2“ 或 ”\\server“ 會傳回 FALSE

範例

#include <windows.h>
#include <iostream.h>
#include "Shlwapi.h"

void main( void )
{
// String path name 1.
char buffer_1[ ] = "C:\\";
char *lpStr1;
lpStr1 = buffer_1;

// String path name 2.
char buffer_2[ ] = "path\\file";
char *lpStr2;
lpStr2 = buffer_2;

// Variable to get the return from "PathIsRoot".
int retval;

// Test case with path not absolute.
retval = PathIsRoot(lpStr1);
cout << "The return from function is       :" << retval << endl;
cout << "The path does contain a root part :" << lpStr1 << endl;

// Test case with path absolute.
retval = PathIsRoot(lpStr2);
cout << "The return from function is       :" << retval << endl;
cout << "The path does not contain part    :" << lpStr2 << endl;
}

OUTPUT:
============
The return from function is       :1
The path does contain a root part :C:\
The return from function is       :0
The path does not contain part    :path\file
============

注意

shlwapi.h 標頭會將PathIsRoot定義為別名,根據UNICODE預處理器常數的定義,自動選取此函式的ANSI或 Unicode 版本。 混合使用編碼中性別名與非編碼中性的程序代碼,可能會導致編譯或運行時間錯誤不符。 如需詳細資訊,請參閱 函式原型的慣例

規格需求

需求
最低支援的用戶端 Windows 2000 專業版、Windows XP [僅限傳統型應用程式]
最低支援的伺服器 Windows 2000 Server [僅限傳統型應用程式]
目標平台 Windows
標頭 shlwapi.h
程式庫 Shlwapi.lib
Dll Shlwapi.dll (4.71 版或更新版本)