Wednesday, October 20, 2010

Old School WScript to Make Files Read-Write

If you frequently need to change the file attributes of one or more files from "Read Only" to "Read and Write" on Windows (like I have to do when dealing with the limitation of Visual SourceSafe), this quickie script will do the trick. Create a .vbs file with the following:

Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim arrayFileObjects(1)
set arrayFileObjects(0) = objFSO.GetFile("C:\BudgetTracker\App.config")
set arrayFileObjects(1) = objFSO.GetFile("C:\ApeSim\App.config")

for counter = 0 to ubound(arrayFileObjects)
if arrayFileObjects(counter).Attributes AND 1 then
'read-only, so set to read/write
arrayFileObjects(counter).Attributes = arrayFileObjects(counter).Attributes XOR 1
Wscript.echo ("one changed")
else
Wscript.echo ("one already ok")
End If

next

No comments: