对于FindFirstFileEx文件系统的支持,限制目录文件系统、目录、FindFirstFileEx

2023-09-04 00:53:46 作者:北巷南猫

我使用的是Windows API函数 FindFirstFileEx 因为它提供的能力以返回给定目录的只是子目录(忽略文件)。然而,当我调用该函数所需的标志,我仍然收到文件和目录。

MSDN文档的 FindExSearchLimitToDirectories 使用FindFirstFileEx标志说:

  

这是一个咨询的标志。如果文件   系统支持目录的筛选,   为一个文件的函数搜索那   与指定名称匹配,也   一个目录。如果文件系统不   不支持目录的筛选,这   标志被忽略。

     

的的lpSearchFilter参数   FindFirstFileEx功能必须为NULL   当这个搜索值被使用。

     

如果目录中筛选需要,   这个标志可以在所有文件中使用   系统,但由于它是一个咨询   旗,只影响文件系统   支持它,应用程序必须   检查存储在文件的属性数据   在的的lpFindFileData参数   FindFirstFileEx函数来确定   该功能是否已返回   处理到一个目录。

那么,什么文件系统真正支持这个标志?这本来是明智的实际列出同一页上这些受支持的文件系统,但我不能找到它。

我开发的系统是Windows XP SP3,NTFS,.NET 3.5。

我知道我可以检查文件属性,以确定是否一个文件是一个目录,但是这意味着检查每个文件/目录。它还击败摆在首位使用FindFirstFileEx的目的。

当然,

还有我可能不正确地做一些在我的code中的机会。我能看到的是经过IntPtr.Zero到lpSearchFilter唯一可能不一样传递NULL(中提到的报价)。

下面是我使用的code的例子:

  m_searchDirHandle = WinAPI.FindFirstFileEx(@C:\ TEMP \ *,
       WinAPI.FINDEX_INFO_LEVELS.FindExInfoStandard,
       裁判m_findDirData,WinAPI.FINDEX_SEARCH_OPS.FindExSearchLimitToDirectories,
       IntPtr.Zero,0);

    如果(m_searchDirHandle!= WinAPI.INVALID_HANDLE_VALUE)
    {
        做
        {
            foundNextDir = WinAPI.FindNextFile(m_searchDirHandle,楼盘m_findDirData);

        }而(foundNextDir);
    }
 
Bica File Renamer 1.3下载 Bica File Renamer 1.3下载 快猴软件下载

解决方案

我能找到最近的联系是,系统的列表中调用由的 Metasploit的 ...我采取了刀伤在这里,但我可以想象,这种FindFirstFileEx会以某种方式是在NT系统调用相当于一个间接调用 NtOpenDirectoryObject','NtQueryDirectoryFile','NtQueryDirectoryObject......我希望......如果有人认为我错了,并downvotes不同意,我将谁不同意予以纠正:)

不过,我已经打在几个环节在这里

codeGuru 论坛在这个问题上有关该标志 葡萄酒具有列为标志邮件因为没有效果? GenNT 提到,这显然是仅限于NTFS,(有3回复到发帖) 在这里的SO,上一个问题如何得到这个文件夹中的文件夹列表

编辑:刚才提的意见后,我认为这将是足够的配件添加链接的 Linux的NTFS驱动程序的功能来读取NTFS分区,也必将是源版本的变化,以适应不同的NTFS版本可以追溯到Win2000的...

希望这会有所帮助, 诚挚的问候, 汤姆。

I am using the Windows API function FindFirstFileEx because it provides the capability to return just the sub-directories of a given directory (ignoring files). However when I call this function with the required flag, I still receive both files and directories.

The MSDN documentation for the FindExSearchLimitToDirectories flag used by FindFirstFileEx says:

This is an advisory flag. If the file system supports directory filtering, the function searches for a file that matches the specified name and is also a directory. If the file system does not support directory filtering, this flag is silently ignored.

The lpSearchFilter parameter of the FindFirstFileEx function must be NULL when this search value is used.

If directory filtering is desired, this flag can be used on all file systems, but because it is an advisory flag and only affects file systems that support it, the application must examine the file attribute data stored in the lpFindFileData parameter of the FindFirstFileEx function to determine whether the function has returned a handle to a directory.

So, what file systems actually support this flag? It would have been sensible to actually list these supported file systems on the same page, but I can't find it.

My development system is Windows XP SP3, NTFS, .NET 3.5.

I know I can check file attributes to determine if a file is a directory, however this means checking the every file/directory. It also defeats the purpose of using FindFirstFileEx in the first place.

Of course there is still the chance I may be doing something incorrectly in my code. The only thing I can see is passing IntPtr.Zero to lpSearchFilter may not be the same as passing NULL (as mentioned in the quote).

Here's an example of the code I'm using:

    m_searchDirHandle = WinAPI.FindFirstFileEx(@"C:\Temp\*",
       WinAPI.FINDEX_INFO_LEVELS.FindExInfoStandard , 
       ref m_findDirData, WinAPI.FINDEX_SEARCH_OPS.FindExSearchLimitToDirectories,
       IntPtr.Zero , 0);

    if (m_searchDirHandle != WinAPI.INVALID_HANDLE_VALUE)
    {
        do
        {
            foundNextDir = WinAPI.FindNextFile(m_searchDirHandle, ref m_findDirData);

        } while (foundNextDir);
    }

解决方案

The nearest link I could find was, the list of System Calls by Metasploit...I am taking a stab here but I would imagine that this 'FindFirstFileEx' would somehow be an indirect call to the NT system call equivalent 'NtOpenDirectoryObject', 'NtQueryDirectoryFile', 'NtQueryDirectoryObject'... I hope...if anyone thinks I'm wrong and downvotes to disagree, I will be corrected by whoever disagrees :)

However, I have hit on a few links here

CodeGuru forum on this issue about the flag Wine has a mailing listed as the flag as no effect? GenNT mentions that it is apparently limited to NTFS, (there's 3 replies to that posting) Here on SO, a question on 'How to get list of folders in this folder'

Edit: Just now after mentioning in the comments, I thought it would be fitting enough to add a link to the Linux NTFS driver for capabilities to read the NTFS partition, there is bound to be source version changes to accomodate the different NTFS versions going back to Win2000...

Hope this helps, Best regards, Tom.