опубликован 12-12-2001 14:08 MSK
unit FindFile;interface
uses Windows, SysUtils, Classes, Masks;
procedure GetLogicalDriveList(const List: TStrings);
procedure GetFixedDriveList(const List: TStrings);
procedure FindFiles(Path, Mask: string; List: TStrings; IncludeSubDir: Boolean = True);
implementation
procedure GetLogicalDriveList(const List: TStrings);
var
Size, Pos: Cardinal;
Buffer: array[0..127] of AnsiChar;
P: PChar;
begin
List.BeginUpdate;
try
List.Clear;
Size:=GetLogicalDriveStrings(SizeOf(Buffer), Buffer);
Pos:=0;
while Pos<Size do begin
P:=@Buffer[Pos];
List.Add(P);
while Buffer[Pos]<>#0 do Inc(Pos);
Inc(Pos);
end;
finally
List.EndUpdate;
end;
end;
procedure GetFixedDriveList(const List: TStrings);
var
Size, Pos: Cardinal;
Buffer: array[0..127] of AnsiChar;
P: PChar;
begin
List.BeginUpdate;
try
List.Clear;
Size:=GetLogicalDriveStrings(SizeOf(Buffer), Buffer);
Pos:=0;
while Pos<Size do begin
P:=@Buffer[Pos];
if GetDriveType(P) = DRIVE_FIXED then List.Add(P);
while Buffer[Pos]<>#0 do Inc(Pos);
Inc(Pos);
end;
finally
List.EndUpdate;
end;
end;
procedure FindFiles(Path, Mask: string; List: TStrings; IncludeSubDir: Boolean = True);
var
SearchRec: TSearchRec;
FindResult: Integer;
begin
List.BeginUpdate;
try
Path:=IncludeTrailingBackSlash(Path);
FindResult:=FindFirst(Path+'*.*', faAnyFile, SearchRec);
try
while FindResult = 0 do with SearchRec do begin
if (Attr and faDirectory<>0) then begin
if IncludeSubDir and (Name<>'..') and (Name<>'.')
then FindFiles(Path+Name, Mask, List, IncludeSubDir);
end else begin
if MatchesMask(Name, Mask) then List.Add(Path+Name);
end;
FindResult:=FindNext(SearchRec);
end;
finally
FindClose(SearchRec);
end;
finally
List.EndUpdate;
end;
end;
end.