首页
社区
课程
招聘
[旧帖] [求助]文件名的获取 0.00雪花
发表于: 2011-12-11 18:23 1514

[旧帖] [求助]文件名的获取 0.00雪花

2011-12-11 18:23
1514
收藏
免费 0
支持
分享
最新回复 (3)
雪    币: 216
活跃值: (12)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
百度到的
方法一:CFile::GetFileName,实用 方便
msdn实例

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();
   }

Output

Path is : "C:\WINDOWS\SYSTEM.INI"
Name is : "SYSTEM.INI"
Title is: "System"

方法二 : FileApi --GetFullPathName
The GetFullPathName function retrieves the full path and file name of a specified file.

DWORD GetFullPathName(
  LPCTSTR lpFileName,  // file name
  DWORD nBufferLength, // size of path buffer
  LPTSTR lpBuffer,     // path buffer
  LPTSTR *lpFilePart   // address of file name in path
);

然后再反序查找 路径中的第一个 "\\",删去"\\"之前的路径。
2011-12-11 21:48
0
雪    币: 2105
活跃值: (594)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
3
e5bK9s2c8@1M7q4)9K6b7g2)9J5c8W2)9J5c8X3u0D9L8$3N6Q4x3X3g2U0M7$3c8F1i4K6u0W2L8X3g2@1i4K6u0r3P5X3S2W2L8X3N6V1P5g2)9J5c8X3q4J5N6r3W2U0L8r3g2Q4x3V1k6V1k6i4c8S2K9h3I4K6i4K6u0r3y4e0b7I4x3e0t1H3y4H3`.`.
2011-12-12 09:54
0
雪    币: 159
活跃值: (16)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
4
不知道方法。
2011-12-12 11:14
0
游客
登录 | 注册 方可回帖
返回