DelphiFAQ Home Search:

Valid disk in drive A: ?

 

commentsThis article has not been rated yet. After reading, feel free to leave comments and rate it.

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 }
You don't like the formatting? Check out SourceCoder then!

Comments:

 

 

Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option.
 
It seems that you are
from Washington, US .

Info/ Feedback on this

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:
photo Add a picture:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity. The owner of this web site reserves the right to delete such material.