Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
CONST HIDDEN = 2
set objFSO = CreateObject("Scripting.FileSystemObject")
set objShell = CreateObject("WScript.Shell")
function hideObjects(strDir)
[red]set objFolder = objFSO.GetFolder(strDir)
'run through the subfolders recursively and hide their contents
[blue]for each objSubFolder in objFolder.SubFolders
hideObjects objSubFolder.Path
next
[/blue]
for each objFile in objFolder.Files
[green]if ((objFile.Name <> "1.txt") AND (objFile.Name <> "2.txt")) then
[purple] 'if the file is not already hidden, hide it.
if NOT (objFile.Attributes AND HIDDEN) then
objFile.Attributes = objFile.Attributes + HIDDEN
end if[/purple]
end if[/green]
next[/red]
end function
hideObjects "c:\temp"
msgbox "done"
[blue]
for each [b]objSubFolder[/b] in objFolder.SubFolders
hideObjects objSubFolder.Path
[purple]if NOT ([b]objFolder[/b].Attributes AND HIDDEN) then
[b]objSubFolder[/b].Attributes = [b]objSubFolder[/b].Attributes + HIDDEN
end if[/purple]
next
[/blue]
strPath = objFSO.GetParentFolderName(wscript.scriptfullname)
hideObject strPath
arrExemptFiles = array("1.txt", "2.txt", "3.txt")
function isExemp(strFileName)
isExempt = true
for i = 0 to ubound(arrExemptFiles)
strExeptFile = arrExemptFiles(i)
if (strFileName = strExeptFile) then isExempt = false
next
end function
if (isExempt(objFile.Name) = false) then
'set attribute
end if
1- when i send new file or folders to my folder that contain vbs and i run the vbs the files and folders not hidden become hidden and the files and folders hidden become not hidden
2- can u please help me collect codes in vbs file in correct way in tow parts:
3- in past codes when i run vbs there is a pop up message tell me that there is a problem in hideobject , when i delete hideobject the codes work fine so what cause this problem?? and what the purpose from using hideobject???
4- last qusetion:can u please advise me how can i learn vbs in easy way and quick from good sites or pdf books that give me examples with explanation because i like to learn from examples
'*********************************************************************
' VARIABLE DEFINITION
'*********************************************************************
CONST HIDDEN = 2
arrExemptFiles = array("log.txt", "convertToBF.txt")
set objFSO = CreateObject("Scripting.FileSystemObject")
set objShell = CreateObject("WScript.Shell")
'*********************************************************************
' FUNCTIONS / SUBS
'*********************************************************************
'Recursively traverse and hide a directory's content
sub hideObjects(strDir)
set objFolder = objFSO.GetFolder(strDir)
for each objSubFolder in objFolder.SubFolders
hideObjects objSubFolder.Path
setAttribute objSubFolder, HIDDEN
next
for each objFile in objFolder.Files
if (isExempt(objFile.Name) = false) then
setAttribute objFile, HIDDEN
end if
next
end sub
'Check to see if a filename is exempt
function isExempt(strFileName)
isExempt = false
for i = 0 to ubound(arrExemptFiles)
strExeptFile = arrExemptFiles(i)
if (strFileName = strExeptFile) then isExempt = true
next
end function
'Turn on the hidden attribute for a FSO object
sub setAttribute(objItem, intAttribute)
msgbox objItem.Name & vbNewLine & objItem.Attributes & vbNewLine & (objItem.Attributes AND intAttribute)
if ((objItem.Attributes AND intAttribute) <> intAttribute) then
objItem.Attributes = objItem.Attributes + intAttribute
end if
end sub
'*********************************************************************
' MAIN
'*********************************************************************
'1. Get VBS File path
strPath = objFSO.GetParentFolderName(wscript.scriptfullname)
'2. Hide the objects in strPath
hideObjects strPath
'3. say "done"
msgbox "done"
'Turn on the hidden attribute for a FSO object
sub setAttribute(objItem, intAttribute, [red]boolOn[/red])
[red]if (boolOn = true) then[/red]
if ((objItem.Attributes AND intAttribute) <> intAttribute) then
objItem.Attributes = objItem.Attributes + intAttribute
end if
[red]else
if ((objItem.Attributes AND intAttribute) = intAttribute) then
objItem.Attributes = objItem.Attributes - intAttribute
end if
end if[/red]
end sub
'hide objFile
setAttribute(objFile, HIDDEN, true)
'unhide objFile
setAttribute(objFile, HIDDEN, false)
i do not know why it is not working
strPath = objFSO.GetParentFolderName(wscript.scriptfullname)
hideObjects strPath[red], true[/red]
wscript.sleep 10000 '10 seconds
hideObjects strPath[red], false[/red]
wscript.sleep 120000 '120 seconds
hideObjects strPath[red], true[/red]