我写这样的代码:
CFile ff;
CString m_fineName = "D:\\gbcab\\gbset.exe";
if(!ff.Open(m_fineName, CFile::modeWrite))
MessageBox("文件"+m_fineName+"不能打开");
else
{
CString sFileTitle = ff.GetFileTitle( );
MessageBox(sFileTitle);
ff.Close();
}
得到的SFileTitle是gbset.exe,不知道是问什么
CFile ff;
CString m_fineName = "D:\\gbcab\\gbset.exe";
if(!ff.Open(m_fineName, CFile::modeWrite))
MessageBox("文件"+m_fineName+"不能打开");
else
{
CString sFileTitle = ff.GetFileTitle( );
MessageBox(sFileTitle);
ff.Close();
}
得到的SFileTitle是gbset.exe,不知道是问什么
CFile::GetFileName
This method retrieves the name of a specified file. For example, when you call GetFileName to generate a message to the user about the file C:\Windows\Write\Myfile.wri, the file name, Myfile.wri, is returned. To return the entire path of the file, including the name, call GetFilePath. To return the title of the file, in this example, myfile, call GetFileTitle.virtual CString GetFileName( )
const;
Return Value
The name of the file.Example
This code fragment opens the System.ini file in your Windows directory. If found, the example prints out the name and path and title, as shown under Output:Try
{
// Try to open the file.
CFile sysFile(_T("\\My Documents\\FOO.DAT"), CFile::modeRead); // Print out path name and title information.
_tprintf(_T("Path is : \"%s\"\n"), (LPCTSTR) sysFile.GetFilePath());
_tprintf(_T("Name is : \"%s\"\n"), (LPCTSTR) sysFile.GetFileName());
_tprintf(_T("Title is: \"%s\"\n"), (LPCTSTR) sysFile.GetFileTitle()); // Close the file handle.
sysFile.Close();
}
CATCH(CFileException* pEx)
{
// If an error occurs, just make a message box.
pEx->ReportError();
}Output
Path is : "\My Documents\FOO.DAT"
Name is : "FOO.DAT"
Title is: "FOO.DAT"Requirements
Windows CE versions: 1.0 and later
Header file: Declared in Afx.h
Platform: H/PC Pro, Palm-size PC, Pocket PCSee Also
CFile::GetFilePath, CFile::GetFileTitle Built on Friday, January 12, 2001
CFile::GetFileTitle
virtual CString GetFileTitle( ) const;Return ValueThe title of the specified file.ResCall this member function to retrieve the file title for a specified file. For example, when you call GetFileTitle to generate a message to the user about the file c:\windows\write\myfile.wri, the file title (myfile) is returned.
你那个是什么版本的?
ExampleThis code fragment opens the SYSTEM.INI file in your WINDOWS directory. If found, the example will print out the name and path and title, as shown under Output:try
{
// try to open the file
CFile sysFile(_T("C:\\WINDOWS\\SYSTEM.INI"), CFile::modeRead); // print out path name and title information
_tprintf(_T("Path is : \"%s\"\n"), (LPCTSTR) sysFile.GetFilePath());
_tprintf(_T("Name is : \"%s\"\n"), (LPCTSTR) sysFile.GetFileName());
_tprintf(_T("Title is: \"%s\"\n"), (LPCTSTR) sysFile.GetFileTitle()); // close the file handle
sysFile.Close();
}
catch (CFileException* pEx)
{
// if an error occurs, just make a message box
pEx->ReportError();
pEx->Delete();
}OutputPath is : "C:\WINDOWS\SYSTEM.INI"
Name is : "SYSTEM.INI"
Title is: "System"CFile Overview | Class Members | Hierarchy Chart
在重粘一次:
CFile::GetFileName
virtual CString GetFileName( ) const;Return ValueThe name of the file.ResCall this member function to retrieve the name of a specified file. For example, when you call GetFileName to generate a message to the user about the file c:\windows\write\myfile.wri, the filename, myfile.wri, is returned.To return the entire path of the file, including the name, call GetFilePath. To return the title of the file (myfile), call GetFileTitle.ExampleThis code fragment opens the SYSTEM.INI file in your WINDOWS directory. If found, the example will print out the name and path and title, as shown under Output:try
{
// try to open the file
CFile sysFile(_T("C:\\WINDOWS\\SYSTEM.INI"), CFile::modeRead); // print out path name and title information
_tprintf(_T("Path is : \"%s\"\n"), (LPCTSTR) sysFile.GetFilePath());
_tprintf(_T("Name is : \"%s\"\n"), (LPCTSTR) sysFile.GetFileName());
_tprintf(_T("Title is: \"%s\"\n"), (LPCTSTR) sysFile.GetFileTitle()); // close the file handle
sysFile.Close();
}
catch (CFileException* pEx)
{
// if an error occurs, just make a message box
pEx->ReportError();
pEx->Delete();
}OutputPath is : "C:\WINDOWS\SYSTEM.INI"
Name is : "SYSTEM.INI"
Title is: "System"CFile Overview | Class Members | Hierarchy ChartSee Also CFile::GetFilePath, CFile::GetFileTitle