...check, if a file is on a local drive?

Author: Cyrus

Category: Files

function IsOnLocalDrive(aFileName: string): Boolean;
var
  
aDrive: string;
begin
  
aDrive := ExtractFileDrive(aFileName);
  if (GetDriveType(PChar(aDrive)) = DRIVE_REMOVABLE) or
     
(GetDriveType(PChar(aDrive)) = DRIVE_FIXED) then
    
Result := True
  else
    
Result := False;
end;


// Example, Beispiel:
procedure TForm1.Button1Click(Sender: TObject);
begin
  if 
OpenDialog1.Execute then
    if 
IsOnLocalDrive(OpenDialog1.FileName) then
      
ShowMessage(OpenDialog1.FileName + ' is on a local drive.');
end;

 

printed from
www.swissdelphicenter.ch
developers knowledge base