Hiding a File or Folder
You want to hide a file or folder from view within Windows Explorer.
Using a graphical user interface
Open Windows Explorer.
Browse to the file or folder you want to hide.
Right-click the file or folder and select Properties.
Check the box beside Hidden (to hide) or uncheck the box (to unhide).
Using a command-line interface
To hide a file, use the attrib.exe command:
> attrib +H <Path>
Here is an example:
> attrib +H d:\mysecretscript.vbs
To unhide a file, use the
> attrib -H <Path>
Here is an example:
> attrib -H d:\mysecretscript.vbs
' This code hides or unhides a file. ' ------ 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
There are many operating system files that are hidden by default. Microsoft did this so you don't get yourself into trouble by accidentally editing or deleting important system files. You also may want to do this if you don't want users to see certain files or folders. The files and folders will still be accessible if the users know the full path; they just won't be visible by default in Windows Explorer. That, however, can be easily circumvented. Windows Explorer provides an option to make all hidden files and folders viewable. From the menu, select Tools → Folder Options. Click the View tab. You just need to select Show hidden files and folders and you'll be able to see them. If you truly don't want users to be able to access certain files or folders, your best bet is to restrict access to them via NTFS permissions.
MS KB 141276 (How to View System and Hidden Files in Windows)
View catalog information for Windows Server Cookbook
Return to the WindowsDevCenter.com.