dirList: TStringList; begin memo1.Lines.BeginUpdate; dirList := TStringList.Create; try dwDrivers := GetLogicalDrives; SetLength(sysDir,max_path); SetLength(sysDir,GetSystemDirectory(PAnsiChar(sysDir),MAX_PATH)); sysDir := ExtractFileDrive(sysDir); for I := 0 to 32 - 1 do if 1= ((dwDrivers shr I) and 1) then begin
strDriver :=Chr(65 + i) + ':'; if strDriver <> sysDir then begin //非系统盘 dirList.Add(strDriver); end; end;
while dirList.Count > 0 do begin strCurrentDir := dirList.Strings[0]; dirList.Delete(0);
FillChar(FindFileData,sizeof(TWIN32FindData),0); hFindHandle := FindFirstFile(PAnsiChar(strCurrentDir+'\*.*'),FindFileData); if hFindHandle = INVALID_HANDLE_VALUE then continue; try if (FindFileData.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY) = FILE_ATTRIBUTE_DIRECTORY then begin if (AnsiString(FindFileData.cFileName) <> '.') and (AnsiString(FindFileData.cFileName) <> '..') then begin dirList.Add(strCurrentDir + '\' + AnsiString(FindFileData.cFileName)); end; end else begin if (UpperCase(RightStr(FindFileData.cFileName,4)) = '.EXE') and ((FindFileData.nFileSizeLow > 5*1024*1024) or (FindFileData.nFileSizeHigh <> 0)) then begin //输出 Memo1.Lines.Add(strCurrentDir + '\' + AnsiString(FindFileData.cFileName)); end; end; finally Windows.FindClose(hFindHandle); end; end;
SetLength(sysDir,max_path); //取得系统路径 SetLength(sysDir,GetSystemDirectory(PAnsiChar(sysDir),MAX_PATH)); //取得系统路径所在的盘符,即系统盘 sysDir := ExtractFileDrive(sysDir); for I := 0 to 32 - 1 do if 1= ((dwDrivers shr I) and 1) then begin
strDriver :=Chr(65 + i) + ':'; if strDriver <> sysDir then begin //非系统盘时添加进扫描列表 dirList.Add(strDriver); end; end;