Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing file properties

Status
Not open for further replies.

MCubitt

Programmer
Mar 14, 2002
1,081
GB
In VBS, can I change the property of a file to NOT be read only?

Thanks



There's no need for sarcastic replies, we've not all been this sad for that long!
 
Look at the FileSystemObject, File Object and the .Attributes attribute of the File Object.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
I tried
set f=fso.getfile(objfile)
if f.attributes and 32 then f.attributes = f.attributes - 32

And attributes are now 1 not 33, so it worked but looking at the file (in Windows) it is still read only.



There's no need for sarcastic replies, we've not all been this sad for that long!
 
try f.attributes = 0

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Tom,

Won't that change other characteristics, such as hidden, archives, etc?

I just want to make it not read-only.

Thanks,


There's no need for sarcastic replies, we've not all been this sad for that long!
 
In that case, what about f.attributes = f.attributes - 1

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Have you the OS permission to change file attributes ?
Anyway, you're right with this:
If f.Attributes And 32 Then f.Attributes = A.attributes - 32


Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Yeah I tried, but still stays as read-only. SO not sure it's working.

Do I have to "update" something?

set f=fso.getfile(objfile)
msg=msgbox(objfile & " " & f.attributes)
if f.attributes and 1 then f.attributes = f.attributes - 1




There's no need for sarcastic replies, we've not all been this sad for that long!
 
As a windows user, yes I can change the attribute.

Never mind.. thanks.





There's no need for sarcastic replies, we've not all been this sad for that long!
 
My bad.
The Read-Only Attribute is 1:
If f.Attributes And 1 Then f.Attributes = A.attributes - 1
The values for attribute are:[tt]
Normal 0
ReadOnly 1 R
Hidden 2 H
System 4 S
Volume 8 V
Directory 16 D
Archive 32 A
Alias 64
Compressed 128[/tt]

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top