File attribute bits

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15576
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

File attribute bits

Post by ChrisGreaves »

Word 2003, I admit, but knowing M$, probably going to be true when Word 2056 is released ...

Code: Select all

Sub test()
    Dim strFullName As String
    strFullName = ThisDocument.FullName
    Dim lngFA
    lngFA = GetAttr(strFullName)
    SetAttr strFullName, vbReadOnly
    lngFA = GetAttr(strFullName)
End Sub
If you drop this code into a new DOCument and save the document to a drive, you will find that the first setting of "lngFA =" tells you (32) that the file needs to be archived.
Makes sense.
We just saved it, didn't we?
The next setting of "lngFA =" tells you 1, that is, read-only, and yep, we just set that didn't we?

But what on earth has happened to the Archive bit?

I ran the code again checking in File Explorer with right-click properties and saw the archive bit disappear as the R-O bit was turned on.

I rather think that marking a file read-only is, in many ways, an indication of the file's importance.
So I figure that backing up the file ought to be extra-specially important too.

I'm just saying ....
There's nothing heavier than an empty water bottle

User avatar
HansV
Administrator
Posts: 78369
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: File attribute bits

Post by HansV »

Change the line

Code: Select all

    SetAttr strFullName, vbReadOnly
to

Code: Select all

    SetAttr strFullName, lngFA Or vbReadOnly
That way, you turn on the Read Only flag while leave the other attributes unchanged.
Best wishes,
Hans

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15576
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: File attribute bits

Post by ChrisGreaves »

HansV wrote:Change the line
Oh.
Right.

:StupidMe:

Especially so since I'm used to ANDing bits from the old DIR search.

I think I should get some :snore:
There's nothing heavier than an empty water bottle