我写这样的代码:
         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,不知道是问什么

解决方案 »

  1.   

    GetFilePath( )可以得到文件路径.
      

  2.   

    下面是MSDN上的:
    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
      

  3.   

    我想得到的是gbset,但得到的是gbset.exe我kanMSDN是使说
    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.
      

  4.   

    我发现如果选择了文件夹选项里的隐藏已知文件类型的扩展文件名的话,就是得到gbset
      

  5.   

    但是这样设置以后,换个文件如gbset.dll显示的还是gbset.dll,真的是很搞不明白了
      

  6.   

    我发的MSDN的例子,上面就是得到带扩展名的啊,你的MSDN上居然说得到的是不带的,怎么MSDN还不一样吗??
      

  7.   

    我这个msdn是“MSDN Library - October 2001”
    你那个是什么版本的?
      

  8.   

    发给你看:
    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
      

  9.   

    弄错了,不好意思,我开始粘的那个是CE里的
    在重粘一次:
    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
      

  10.   

    我是要用CFile::GetFileTitle得到文件不带扩展名的文件名,如gbset
      

  11.   

    http://support.microsoft.com/kb/143409/zh-cn