1. Testing Write Access on Windows
- Posted by euphoric (admin) Mar 01, 2013
- 1260 views
What's a good way to test for write access to a directory on Windows? Is there a flag available somewhere, or do I need to attempt to write a file and gauge results based on that?
2. Re: Testing Write Access on Windows
- Posted by mattlewis (admin) Mar 01, 2013
- 1267 views
What's a good way to test for write access to a directory on Windows? Is there a flag available somewhere, or do I need to attempt to write a file and gauge results based on that?
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.
Matt
3. Re: Testing Write Access on Windows
- Posted by ghaberek (admin) Mar 01, 2013
- 1240 views
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
4. Re: Testing Write Access on Windows
- Posted by euphoric (admin) Mar 01, 2013
- 1220 views
If you have 'r' in D_ATTRIBUTES then it's read only.
Thanks, Matt! But...
Is it possible to get the attributes of a particular directory, without having to get the dir(parent_dir_of_target_dir) and searching the results for the dir I need?
Maybe something like a get_attrib( my_dir ) would be nice.