Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Read only file
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Titre:
Divers
Thread ID:
00529877
Message ID:
00534906
Vues:
16
>>>Hi,
>>>
>>>I just ran across your 12/07/2001 Windows Script tip on how to turn on
>>>a file's read-only attribute and was able to successfully turn on a file's
>>>read-only property.
>>>
>>>My actual need is just the opposite. Might you be willing to suggest how
>>>I could turn off the read-only attribute?
>>>
>>>I know virtually nothing about Windows Scripting but found out that the
>>>normal file attribute constant is 0. Simply substituting the constant
>>>0 in place of 1 didn't work. Any help would be appreciated.
>>>
>>>Thank you in advance.
>>>
>>
>>>
>>>(Your original tip)
>>> oFSO = CREATEOBJECT('Scripting.FileSystemObject')
>>> * Get an object reference to the file of interest
>>> oFile = oFSO.GetFile(lcfile)
>>> * Set to Read-Only
>>> oFile.Attributes = BITOR(oFile.Attributes, 1)
>>
>>Sure. Instead of BITOR(), use BITXOR(). The all bit except bit zero will be retained.
>
>Just to clarify George's answer - using BITXOR() will clear the Read-Only attribute if it is already set, otherwise it will set it. To ensure that the read-only bit is cleared, do the BITOR() followed by BITXOR() or use BITAND( oFile.Attributes, BITNOT( 1 ) ) to ensure it is cleared.

Len,

Thanks for posting this. I had mentioned this possibility to Spencer in response to a private message he sent me. I should've done the same here, because it's part of the public record.

An additional piece of information may be in order here. While it's possible to use mathematical operators (addition and subtraction) on the attributes of files or folders, it can under some circumstances lead to an error because of at least one bit being read-only (the directory bit).
George

Ubi caritas et amor, deus ibi est
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform