2012-02-12 88 views
2

我使用哪些Windows内核API从驱动程序获取路径的基本文件名? (我假设我没有寻找最后的字符串“\”)获取文件基本名称

如获得bar.txtc:\foo\bar.txt

回答

2

你可能会考虑使用构建直到FsRtlDissectName其余的路径参数为空循环。

像这样的事情可能会做你想做的(虽然你需要处理的事情像ADS流的名称,以及添加适当的错误检查):

void FetchFileName(IN PUNICODE_STRING pSourceString, OUT PUNICODE_STRING pFileName) 
{ 
    UNICODE_STRING current = *pSourceString; // structure copy. 
    UNICODE_STRING remaining; 
    for(;;) 
    { 
     // Fetch the next path component. 
     FsRtlDissectName(current, pFileName, &remaining); 
     if(remaining.Length == 0) 
     { 
      // Nothing left to parse. pFilename will 
      // contain the last filename found. 
      break; 
     } 

     // Advance down the string. 
     current = remaining;    // structure copy. 
    } 
} 
+0

感谢。看起来正是我需要的 – 2012-02-12 23:46:07