Re: [fpc-pascal] How to get the permission f a file ?
Fred, the tiSetFileReadOnly() I sent you the other day already uses fpstat() before checking/setting the read-only flag. So you are halfway there. ;-) Yep, many thanks. ;-) PS: Bart's tip works like lovely charm... = 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; Fre;D ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How to get the permission f a file ?
On 6/17/15, fredvs fi...@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 ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How to get the permission f a file ?
On 06/17/2015 04:42 PM, fredvs wrote: But how to check if a file has executable permission (and if not, change it with fpchmod(thefile S_IRWXU);) ? stat? See: http://linux.die.net/man/2/stat http://www.freepascal.org/docs-html/rtl/baseunix/fpstat.html http://www.freepascal.org/docs-html/rtl/baseunix/stat.html -- Ewald ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How to get the permission f a file ?
Hi, On Wed, 17 Jun 2015, fredvs wrote: But how to check if a file has executable permission (and if not, change it with fpchmod(thefile S_IRWXU);) ? From the top of my head: fpStat(), and in the returned stat structure, look for the mode field (or st_mode?). There are more useful bits in there. There is also fpFStat() and fpLStat() (for symlinks). There are also several S_* constants in BaseUnix unit for easier testing of various permission combinations. Charlie ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How to get the permission f a file ?
@ Bart and Ewald. = excellent, many thanks. And you give me choice...;-) I will study your tips and then choose one of them... Many thanks. Fre;D - Many thanks ;-) -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/How-to-get-the-permission-f-a-file-tp5721836p5721840.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How to get the permission f a file ?
On 2015-06-17 16:00, fredvs wrote: And you give me choice...;-) I will study your tips and then choose one of them... Fred, the tiSetFileReadOnly() I sent you the other day already uses fpstat() before checking/setting the read-only flag. So you are halfway there. ;-) Regards, - Graeme - -- fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal