I'm trying to delete a file via vbscript, but I'm getting stumped by something that should be easy. As you can see from my code snippet, I want to make sure that the old file I want to remove is not read-only. However, the line "If objFile.Attributes = objFile.Attributes AND 1 Then" always seems to be evaluated true, because the read-only attribute gets flipped, whether it was originally set or not. (The MsgBox lines are just tracing for me while I troubleshoot.)
What am I doing wrong?
' remove old pcf file
' make sure if there is an existing file it is not read-only so that DeleteFile works
If objFSO.FileExists(sOldFile) Then
Set objFile = objFSO.GetFile(sOldFile)
If objFile.Attributes = objFile.Attributes AND 1 Then
objFile.Attributes = objFile.Attributes XOR 1
MsgBox "fixed read-only old file"
MsgBox "not read-only old file"
MsgBox "old pcf deleted"
MsgBox "old file not previously existing"