Udostępnij za pośrednictwem


CFileFind::GetFileName

Call this member function to get the name of the found file.

virtual CString GetFileName( ) const;

Return Value

The name of the most-recently-found file.

Remarks

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 name myfile.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 path c:\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 title myfile.

Example

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

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

Requirements

Header: afx.h

See Also

Reference

CFileFind Class

Hierarchy Chart

CFileFind::FindFile

Other Resources

CFileFind Members