Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Change file attribute
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00544743
Message ID:
00544783
Vues:
20
>>>>Hi people.
>>>>How can i change file attribute from read only to write and back?
>>>>Thank you
>>>
>>>You can do this with the FileSystemObject:
>>>
oFSO = CreateObject("Scripting.FileSystemObject")
>>>oFile = oFSO.GetFile("d:\temp\package.txt")
>>> To set it to read only:
>>>
oFile.Attributes = oFile.Attributes + 1
>>> To clear the read only:
>>>
oFile.Attributes = oFile.Attributes - 1
>>> Where 1 is the attribute value for the file's read-only flag.
>>>
>>>HTH
>>
>>J.,
>>
>>Noooo!:-) It's a bad idea. The reason I say this is: If it isn't read-only and you subtract 1, you'll modify the other bits too. Same thing with adding. Further, with the folder object at least, the directory bit is read-only and will error on you. Use the bitwise operators always.
>
>I see. I suppose you need to check the setting first if you want to go this way.

Yep, but, if I recall correctly, if it's a folder object, rather than a file object, you'll generate an error anyway. Since they're so similar, if you were writing a routine to change the attributes, you'd want to abstract it so that it could work with either. In order to do so, you'd use the bit manipulation functions. Dino Esposito mentions this problem, BTW, in the "Windows Script Host Programmers Reference" from Wrox, which I'd highly recommend.

>Thanks.

No prob.
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