Re: Testing Write Access on Windows
- Posted by ghaberek (admin) Mar 01, 2013
- 1242 views
mattlewis said...
Use dir():
include std/filesys.e sequence c = dir( `C:\` ) for i = 1 to length( c ) do if find( 'd', c[i][D_ATTRIBUTES] ) then printf(1, "%s: %s\n", { c[i][D_NAME], c[i][D_ATTRIBUTES] }) end if end for
If you have 'r' in D_ATTRIBUTES then it's read only.
But that's only going to tell you if the directory is marked "Read only". Other file security restrictions could still apply, making the directory effectively read-only. You may be able to use the PrivilegeCheck function to check your permissions, but I am not entirely sure how to do that. Another approach would be to pull the ACL from the directory with GetSecurityInfo and look for Write and/or Modify rights for your user or group.
Or, you know, just test by trying to write a file.
-Greg