procedure GetDriveLetters(AList: TStrings);
var
vDrivesSize : Cardinal;
vDrives : array[0..128] of Char;
vDrive : PChar;
begin
AList.BeginUpdate;
try
AList.Clear;
vDrivesSize := GetLogicalDriveStrings(SizeOf(vDrives), vDrives);
if vDrivesSize = 0 then Exit;
vDrive := vDrives;
while vDrive^ <> #0 do
begin
AList.Add(StrPas(vDrive));
Inc(vDrive, SizeOf(vDrive));
end;
finally
AList.EndUpdate;
end;
end;
function FindFolderOnDrives(sFolderName : String):string;
var
i : Integer;
lDrivers : TStringList;
sFolderPath : String;
begin
Result := '';
lDrivers := TStringList.Create;
try
GetDriveLetters(lDrivers);
for i := 0 to lDrivers.Count - 1 do
begin
sFolderPath := lDrivers[i] + sFolderName;
if DirectoryExists(sFolderPath) then
begin
Result := sFolderPath;
Exit;
end;
end;
finally
lDrivers.Free;
end;
end;
Пример использования
procedure TForm1.Button1Click(Sender: TObject);
begin
Edit1.Text := FindFolderOnDrives('ASDFG');
end;