VBcoders Browse New Submit Contact Sign In

No account? Register free

Forgot password?

Setting and getting file attributes w/o affecting other attributes Updated

Rde  (54 Submissions)   Files/File Controls/Input/Output   VB Script   Beginner   Wed 3rd February 2021

These two simple wrappers can be used for setting and retrieving individual or selected file attributes without affecting the other attributes of the file. For example, to set the Archive bit of a file you should not just set its attributes to vbArchive (32), as this will turn off any other attributes currently set. Normally you would need to get the file attributes, add the desired attribute to the current attributes, then set them again. These wrappers just hide the details of this process. Update thanks to redbird77.
+++++++++++++++++++++++++++++++++++++++++++++++++++
With the GetAttrib wrapper you can easily test the current state of an attribute. You simply specify the attribute(s) and the function will return True if the specified attribute(s) is set to on. You can specify more than one attribute and True will be returned only if all specified attributes are turned on.
+++++++++++++++++++++++++++++++++++++++++++++++++++
The SetAttrib wrapper simplifies the setting of an attribute to on or off, and will be set as desired irrespective of its current state. You can set more than one attibute at a time (eg. SetAttrib(sFile, vbReadOnly Or vbHidden) will set these attributes to on, no matter if they are on or off, without affecting other attributes that may be set.
+++++++++++++++++++++++++++++++++++++++++++++++++++
My first version of the SetAttrib function used 'Xor' to turn attributes off, but thanks to redbird77, I have updated it to 'Not' which has eliminated a limitation of my version. The bottom line is that you can set a files attribute(s) to on or off without needing to know the current state of the specified attributes, while not affecting other attributes that may be set.

Rate Setting and getting file attributes w/o affecting other attributes Updated (4(4 Vote))
Setting and getting file attributes w/o affecting other attributes Updated.bas

Setting and getting file attributes w/o affecting other attributes Updated Comments

No comments yet — be the first to post one!

Post a Comment

0/1000 characters