Remove Read Only

W

Wendy

Hi

I'm trying to delete a file programatically, its set as readonly, I can't
find the fso option to do this can anyone help please? This is what I've
got upto now.

thanks

Wendy

If (fso.FileExists(destnewsfile)) then fso.deletefile (destnewsfile)
 
D

Douglas J. Steele

That's probably overkill. VBA includes the SetAttr statement that will let
you change the attributes of a file.

To remove a file's Read-only attribute, while leaving the other attributes
the same, you can use:

SetAttr "full path to file", (GetAttr("full path to file") - vbReadOnly)
 
D

Douglas J. Steele

Yup.

No need for FSO at all, is there? <g>

Dim intAttribute As Integer

If Len(Dir(destnewsfile)) > 0 Then
intAttribute = GetAttr(destnewfile)
If (intAttribute And vbReadOnly) <> 0 Then
SetAttr destnewfile, (intAttribute - vbReadOnly)
End If
Kill destnewsfile
End If
 
T

Tim Ferguson

That's probably overkill. VBA includes the SetAttr statement that will
let you change the attributes of a file.

To remove a file's Read-only attribute, while leaving the other
attributes the same, you can use:

SetAttr "full path to file", (GetAttr("full path to file") -
vbReadOnly)

That's probably overkill too. My help file says that the .Delete method of
the File object has a Force parameter that will kill readonly files...


Set fil = fso.GetFile(somePathString)
fil.Delete True


Hope that helps


Tim F
 
D

Douglas J. Steele

Tim Ferguson said:
That's probably overkill too. My help file says that the .Delete method of
the File object has a Force parameter that will kill readonly files...


Set fil = fso.GetFile(somePathString)
fil.Delete True

You're right, but I don't like using FSO when it's not necessary!

Being picky, Wendy could simply use:

If (fso.FileExists(destnewsfile)) then fso.deletefile destnewsfile, True
 
Top