This function returns whether a drive's state = whether it contains
no disk
an unformatted disk
an empty disk
a disk with files
type
TDriveState = (DSNODISK, DSUNFORMATTEDDISK, DSEMPTYDISK, DSDISK_WITHFILES);
function DriveState (driveletter: Char) : TDriveState;
var
mask: String[6];
sRec: TSearchRec;
oldMode: Cardinal;
retcode: Integer;
begin
oldMode: = SetErrorMode(SEM_FAILCRITICALERRORS);
mask:= '?:\*.*';
mask[1] := driveletter;
{$I-}
retcode := FindFirst (mask, faAnyfile, SRec);
FindClose(SRec);
{$I+}
case retcode of
0: Result := DSDISK_WITHFILES; { at least one file was found }
-18: Result := DSEMPTYDISK; { no files, but disk is ok }
-21, -3: Result := DSNODISK; { DOS ERRORNOTREADY in WinNT,
ERRORPATH_NOTFOUND in 3.1 }
else
Result := DSUNFORMATTEDDISK; { unformatted disk in drive }
end;
SetErrorMode(oldMode);
end; { DriveState }