Mega Code Archive

 
Categories / Delphi / Files
 

How to check, if a file is on a local drive

Title: How to check, if a file is on a local drive 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; Usage Example: procedure TForm1.Button1Click(Sender: TObject); begin if OpenDialog1.Execute then if IsOnLocalDrive(OpenDialog1.FileName) then ShowMessage(OpenDialog1.FileName + ' is on a local drive.'); end;