ProblemYou want to hide a file or folder from view within Windows Explorer. SolutionUsing a graphical user interface
Using a command-line interfaceTo 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 -H option: > attrib -H <Path> Here is an example: > attrib -H d:\mysecretscript.vbs Using VBScript' 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 DiscussionThere 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. See AlsoMS KB 141276, "How to View System and Hidden Files in Windows" |