Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
virtual CString GetFileName( ) const;
Return Value
The name of the most-recently-found file.
Remarks
Call this member function to get the name of the found file. You must call FindNextFile at least once before calling GetFileName.
GetFileName is one of three CFileFind member functions that return some form of the file name. The following list describes the three and how they vary:
GetFileName returns the file name, including the extension. For example, calling GetFileName to generate a user message about the file
c:\myhtml\myfile.txt
returns the file namemyfile.txt
.GetFilePath returns the entire path for the file. For example, calling GetFilePath to generate a user message about the file
c:\myhtml\myfile.txt
returns the file pathc:\myhtml\myfile.txt
.GetFileTitle returns the file name, excluding the file extension. For example, calling GetFileTitle to generate a user message about the file
c:\myhtml\myfile.txt
returns the file titlemyfile
.
Example
CFileFind finder;
static const TCHAR szFileToFind[] = _T("C:\\WINDOWS\\SYSTEM.INI");
BOOL bResult = finder.FindFile(szFileToFind);
if (bResult)
{
finder.FindNextFile();
cout << "Root of " << szFileToFind;
cout << " is " << (LPCTSTR) finder.GetRoot();
cout << endl;
cout << "Title of " << szFileToFind;
cout << " is " << (LPCTSTR) finder.GetFileTitle();
cout << endl;
cout << "Path of " << szFileToFind;
cout << " is " << (LPCTSTR) finder.GetFilePath();
cout << endl;
cout << "URL of " << szFileToFind;
cout << " is " << (LPCTSTR) finder.GetFileURL();
cout << endl;
cout << "Name of " << szFileToFind;
cout << " is " << (LPCTSTR) finder.GetFileName();
cout << endl;
finder.Close();
}
else
cout << "You have no " << szFileToFind << " file." << endl;
Example Output
Assumes that the file C:\WINDOWS\SYSTEM.INI exists:
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
CFileFind Overview | Class Members | Hierarchy Chart
See Also CFileFind::FindFile