1. Testing Write Access on Windows

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?

new topic     » topic index » view message » categorize

2. Re: Testing Write Access on Windows

euphoric said...

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

new topic     » goto parent     » topic index » view message » categorize

3. Re: Testing Write Access on Windows

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. blink

-Greg

new topic     » goto parent     » topic index » view message » categorize

4. Re: Testing Write Access on Windows

mattlewis said...

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? smile

Maybe something like a get_attrib( my_dir ) would be nice.

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu