共用方式為


CFileFind::GetFileName

呼叫此成員函式以取得找到的檔案名稱。

virtual CString GetFileName( ) const;

傳回值

名稱的最近發現檔案。

備註

您必須在呼叫之前 GetFileName 至少一次呼叫 FindNextFile

GetFileName 是傳回檔名的某種形式的三 CFileFind 成員函式的其中之一。 下列清單說明三,以及如何變更:

  • GetFileName 傳回檔名,包括副檔名。 例如,呼叫 GetFileName 產生相關檔案的使用者 c:\myhtml\myfile.txt 訊息傳回檔名 myfile.txt。

  • GetFilePath 傳回檔案的完整路徑。 例如,呼叫 GetFilePath 產生相關檔案的使用者 c:\myhtml\myfile.txt 訊息傳回檔案路徑 c:\myhtml\myfile.txt。

  • GetFileTitle 傳回檔案名稱,不包含副檔名。 例如,呼叫 GetFileTitle 產生相關檔案的使用者 c:\myhtml\myfile.txt訊息傳回檔案標頭 myfile。

範例

CFileFind finder;
static const TCHAR szFileToFind[] = _T("C:\\WINDOWS\\SYSTEM.INI");

BOOL bResult = finder.FindFile(szFileToFind);

if (bResult)
{
   finder.FindNextFile();

   TRACE(_T("Root of %s is %s\n"), szFileToFind, 
      (LPCTSTR)finder.GetRoot());

   TRACE(_T("Title of %s is %s\n"), szFileToFind, 
      (LPCTSTR)finder.GetFileTitle());

   TRACE(_T("Path of %s is %s\n"), szFileToFind,
      (LPCTSTR)finder.GetFilePath());

   TRACE(_T("URL of %s is %s\n"), szFileToFind,
      (LPCTSTR)finder.GetFileURL());

   TRACE(_T("Name of %s is %s\n"), szFileToFind,
      (LPCTSTR)finder.GetFileName());

   finder.Close();
}
else
{
   TRACE(_T("You have no %s file.\n"), szFileToFind);
}

Output

舉例來說,假設 C 檔案: \WINDOWS\SYSTEM.INI 存在:

Root of C:\WINDOWS\SYSTEM.INI is C:\WINDOWS

Title of C:\WINDOWS\SYSTEM.INI is SYSTEM

Path of C:\WINDOWS\SYSTEM.INI is C:\WINDOWS\SYSTEM.INI

URL of C:\WINDOWS\SYSTEM.INI is file://C:\WINDOWS\SYSTEM.INI

Name of C:\WINDOWS\SYSTEM.INI is SYSTEM.INI

需求

Header: afx.h

請參閱

參考

CFileFind 類別

階層架構圖表

CFileFind::FindFile