>Any body have idea how I could do this in Delphi4 without too much
>trouble... My problem is that I want to try reading on only
connected
>drive, not drive L if the PC have no Drive L....
You could attach a TDriveComboBox component to your form, and loop through
the Items[] property to look for that label. This will not work
for a
removable drive, but should work otherwise.
If you otherwise do not need a TDriveComboBox component, you could put
it
somewhere invisible and still use the information. I wrote a
component that
I call TDriveInfo that is non-visual (so the user doesn't see it),
but
returns all the info that TDriveComboBox does and more. Let me
know by
private e-mail if you want a copy, letting me know your e-mail address.
----------
The following code lists all available drives along with their type
and
label in listbox:
function GetDiskLabel(const DriveRoot: string): string;
var
VolNameBuffer: array[0..127] of char;
dwFlags, dwComponentLength: dword;
begin
if GetVolumeInformation(
PChar(DriveRoot), // address of root directory of
the file system
@VolNameBuffer, // address of name of the volume
SizeOf(VolNameBuffer), // length of lpVolumeNameBuffer
nil, // address of volume serial number
dwFlags, // address of system's maximum filename
length
dwComponentLength, // address of file system flags
nil, // address of name of file system
0) // length of lpFileSystemNameBuffer
then
Result := String(VolNameBuffer)
else
Result := 'not available';
end;
procedure TForm1.Button1Click(Sender: TObject);
const
DRIVETYPES: array [DRIVE_UNKNOWN..DRIVE_RAMDISK] of string =
('Unknown',
'No root',
'Removable',
'Fixed',
'Remote',
'CD-ROM',
'RAM disk');
var
dwDrives: dword;
btDrive: byte;
wDriveType: word;
sDrive, sDriveInfo: string;
begin
Screen.Cursor := crHourglass;
LB.Clear;
dwDrives := GetLogicalDrives();
if dwDrives <> 0 then begin
for btDrive := 0 to 25 do
if dwDrives and (1 shl btDrive) <>
0 then begin
sDrive := Char(65 + btDrive)
+ ':\';
wDriveType := GetDriveType(PChar(sDrive));
//if wDriveType <> DRIVE_REMOVABLE
then
sDriveInfo := Format('%s
%s, label: %s', [
sDrive,
DRIVETYPES[wDriveType],
GetDiskLabel(sDrive)]);
LB.Items.Add(sDriveInfo);
end;
end;
Screen.Cursor := crDefault;
end;
You can sue this method to get labels of all available drives, store
them
and later search if there is drive with specific label available.
----------