Remove Read Only

  • Thread starter Thread starter Wendy
  • Start date Start date
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)
 
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)
 
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
 
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
 
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
 
Back
Top