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

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

2011-12-11 18:23
1384
仅知道文件的句柄,如何获取文件名?

[课程]Linux pwn 探索篇!

收藏
免费 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
活跃值: (424)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
3
http://blog.csdn.net/zhengdy/article/details/5411207
2011-12-12 09:54
0
雪    币: 159
活跃值: (16)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
4
不知道方法。
2011-12-12 11:14
0
游客
登录 | 注册 方可回帖
返回
//