【发布时间】: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);
【问题讨论】:
-
您能说明一下您是如何使用
FindFirstFile和FindNextFile的吗? -
我认为您的问题类似于这个 SO 问题:stackoverflow.com/questions/8155010/…
-
你为什么不用这个Windows API的Delphi翻译?
-
String(tWDF.cFileName[0]) <> '.')不是一个很好的检查。文件名可以以.开头(如.htaccess),即使 Windows 资源管理器 shell 不允许您输入这样的名称。 -
找不到什么文件?有图案吗?例如是否缺少所有隐藏文件?
标签: delphi winapi windows-7 delphi-xe3