On 5-2-2011 9:11, Reinhard Kotucha wrote:
In order to test whether a file is readable I currently open this file in a protected call. This is also possible for directories when I run lfs.dir() inside pcall(). It's not very elegant, and I still have no idea how to test whether a file is writable. I could try to open the file in append mode, but I fear that if the file is writable, this test would change the time stamps. Not very elegant either.
I use something function file.is_writable(name) local d = string.match(name,"^(.+)[/\\].-$") or "." local a = lfs.attributes(name) or lfs.attributes(d) return a and string/sub(a.permissions,2,2) == "w" end function file.is_readable(name) local a = lfs.attributes(name) return a and string.sub(a.permissions,1,1) == "r" end ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------