On Sunday, September 06, 2015 20:40:03 Gary Willoughby via Digitalmars-d-learn wrote: > Are there any Phobos functions to check file permissions on > Windows and Posix? For example, I want to check if a file is > readable and/or writable in a cross-platform fashion. Does anyone > have an example?
http://dlang.org/phobos/std_file.html#.getAttributes will get you all of the file attributes for a file, though you'll have to look at the Windows and POSIX documentation to know how to interpret that. http://dlang.org/phobos/std_file.html#.DirEntry provides some file attributes in a cross-platform manner, but readability and writability aren't among them (though its attributes property will give you the same thing that getAttributes doe). So, as it stands, it looks like if you want to check for readibility or writability, you'd have to look at the OS documentation for each OS to see how the attributes should be interpreted. So, while you don't have to deal with the C APIs themselves for this, and the function call itself is cross-platform, the result isn't, unfortunately. However, looking over the windows documentation, I suspect that writability is the only attribute which DirEntry doesn't have which could be done cross-platform but isn't. The types of attributes that Windows has are drastically different from those in *nix land, which makes treating some of this stuff in a cross-platform fashion quite difficult. - Jonathan M Davis