【问题标题】:Why the FindFirstFile/FindNextFile does not list the entire content of the system directory on Windows 7?为什么 FindFirstFile/FindNextFile 没有列出 Windows 7 上系统目录的全部内容?
【发布时间】:2012-11-12 20:47:36
【问题描述】:

我有一个小问题。 API FindNextFile 没有列出目录 C:\Windows\System32 的全部内容(仅限 Windows 7)。任何人有任何解决方案?

代码[Delphi]:

Var
  sAtr:       String;
  sPathName:  String;
  I:          Integer;
  iCont:      Integer;
  tHnd:       THandle;
  tArrAtr:    TStringList;
  tWDF:       WIN32_FIND_DATA;
Begin
  iCont := 0;
  sAtr := '';
  Result := TStringList.Create;
  tArrAtr := TStringList.Create;
  tHnd := FindFirstFile(PChar(sPath + '*.*'), tWDF);

  If RightStr(sPath, 1) <> '\' Then
    sPath := sPath + '\';

  If tHnd = INVALID_HANDLE_VALUE Then
    Exit;

  Repeat
    If (tWDF.dwFileAttributes And FILE_ATTRIBUTE_ARCHIVE) > 0 Then
      If (String(tWDF.cFileName[0]) <> '.') Then
      Begin
        sPathName := sPath + String(tWDF.cFileName);

        Result.Add(String(tWDF.cFileName) + sDel +
                   GetFileSizeAPI(sPathName));
        sAtr := '';
        Inc(iCont);
      End;
  Until (FindNextFile(tHnd, tWDF) <> True);

  //CloseHandle(tHnd);

【问题讨论】:

  • 您能说明一下您是如何使用FindFirstFileFindNextFile 的吗?
  • 我认为您的问题类似于这个 SO 问题:stackoverflow.com/questions/8155010/…
  • 你为什么不用这个Windows API的Delphi翻译?
  • String(tWDF.cFileName[0]) &lt;&gt; '.') 不是一个很好的检查。文件名可以以 . 开头(如 .htaccess),即使 Windows 资源管理器 shell 不允许您输入这样的名称。
  • 找不到什么文件?有图案吗?例如是否缺少所有隐藏文件?

标签: delphi winapi windows-7 delphi-xe3


【解决方案1】:

我敢打赌,你有一台 64 位机器和一个 32 位进程。 File System Redirector 进入游戏,System32 重定向到 SysWOW64

避免重定向器的最佳方法是执行 64 位进程。或者您可以列出 Sysnative 以从 32 位进程中获取 64 位系统文件夹。您甚至可以禁用文件系统重定向器,但这样做非常危险,我不建议这样做。

此外,您可以通过调用FindClose 而不是CloseHandle 来整理查找句柄。您应该在调用FindFirstFile 之前添加反斜杠。并通过将全名与这些特殊值进行比较来测试特殊的 ...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多