PDA

View Full Version : Folder Access



Jeevie
08-14-2013, 04:50 AM
Hello All

I need help to figure out the access type to a list of folders as whether Read/write, read only or view only. Is there a way to find using VBA? Appreciate any help.

snb
08-14-2013, 05:22 AM
Sub tst()
MsgBox CreateObject("scripting.filesystemobject").getfolder("G:\OF").Attributes
End Sub

Kenneth Hobs
08-14-2013, 06:10 AM
MsgBox "e:\t: " & ((GetAttr("e:\t") And vbReadOnly) <> 0), vbInformation, "ReadOnly?"
MsgBox "e:\t: " & ((CreateObject("scripting.filesystemobject").GetFolder("e:\t").Attributes And vbReadOnly) <> 0), vbInformation, "ReadOnly?"

Jeevie
08-14-2013, 06:57 AM
Thanks for your replies. There are 3 possibilities. I could have read/write access, read only access where I can read and copy files from, a view only access where I can view files but cannot open or copy them and lastly no access. How do I derive this information. The attributes properties is returning 48 for all the above possibilities.

Kenneth Hobs
08-14-2013, 07:02 AM
I showed how to do it. It is also explained in the help for the VBA command GetAttr. Type GetAttr and press F1 or browse the it by F2 and press F1 when you select it there for more help.

Jeevie
08-14-2013, 11:14 AM
Hi Kenneth

It returns 48 for read only folders. Not sure what the number is. For folders I dont have access to, it returns 48 or nothing at all which is confusing. Also there are some folders where I have view access but not access to copy files from unlike read only folders and it still returns 48.

Kenneth Hobs
08-14-2013, 12:03 PM
Did you look at the help as I advised?

There is no value of 48 for a single attribute. It is a summed number of the attributes that is returned. The help explains how to use the bitwise AND operator to parse out the attribute that you want to check. If the bitwise operationr result is not 0, then the attribute is set. Does my code now make sense?