DelphiFAQ Home Search:
General :: Windows :: Programming :: Windows with Delphi :: Windows Filesystem
File related questions and answers. File operations, attributes, system dialogs, hard disk handling.

Articles:

This list is sorted by recent document popularity (not total page views).
New documents will first appear at the bottom.

Only the 40 most recently viewed articles are shown.
You can see the full list here.

Featured Article

Valid disk in drive A: ?

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!
Generated 8:03:20 on Dec 19, 2018