Hide or unhide a file (VBScript)

This code can be found in Chapter 8 of Windows XP Cookbook

Purchase XP Cookbook or Networking Recipes for only $25 plus shipping! While supplies last.

Find out how to download all of the VBScript code from this site.

' From the book "Windows XP Cookbook"
' ISBN: 0596007256

' ------ SCRIPT CONFIGURATION ------
strFile = "<FilePath>" ' e.g. d:\mysecretscript.vbs
boolHide = True ' True to hide, False to unhide 
' ------ END CONFIGURATION ---------
set objFSO = CreateObject("Scripting.FileSystemObject")

' Change this to GetFolder to hide/unhide a folder
set objFile = objFSO.GetFile(strFile)

if boolHide = True then
 if objFile.Attributes AND 2 then
 WScript.Echo "File already hidden" 
 else
 objFile.Attributes = objFile.Attributes + 2 
 WScript.Echo "File is now hidden"
 end if 
else
 if objFile.Attributes AND 2 then
 objFile.Attributes = objFile.Attributes - 2 
 WScript.Echo "File is not hidden"
 else
 WScript.Echo "File is already not hidden" 
 end if 
end if

This code has been viewed 2432 times.

New from the creators of TechTasks.com: StatSheet.com