[fpc-pascal] How to get the permission f a file ?

Bart bartjunk64 at gmail.com
Wed Jun 17 16:49:35 CEST 2015


On 6/17/15, fredvs <fiens at hotmail.com> wrote:

> But how to check if a file has executable permission (and if not, change it
> with fpchmod(thefile S_IRWXU);) ?

function FileIsExecutable(const AFilename: string): boolean;
var
  Info : Stat;
begin
  // first check AFilename is not a directory and then check if executable
  Result:= (FpStat(AFilename,info{%H-})<>-1) and FPS_ISREG(info.st_mode) and
           (BaseUnix.FpAccess(AFilename,BaseUnix.X_OK)=0);
end;

(From LazFileUtils unit of Lazarus)

Bart



More information about the fpc-pascal mailing list