none
Unhiding the Folder..

    Question

  • Based on the certain request , I have hide specific folder through script which is given below...

    On error resume next
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFolder = objFSO.GetFolder("Folder path")
    If objFolder.Attributes = objFolder.Attributes AND 2 Then
        objFolder.Attributes = objFolder.Attributes XOR 2
     
    End If

    Now I need to revert the case ( UNHIDE ).

    Kindly suggest what modification I need to do in the scritp as i am not getting proper clue to get this rectified.

    Thursday, January 02, 2014 1:22 PM

Answers

  • That's what your code does already - if the folder is hidden, then unhide it.

    Bill

    • Marked as answer by Tech Olive Wednesday, January 15, 2014 12:25 PM
    Thursday, January 02, 2014 2:20 PM
    Moderator

All replies

  • That's what your code does already - if the folder is hidden, then unhide it.

    Bill

    • Marked as answer by Tech Olive Wednesday, January 15, 2014 12:25 PM
    Thursday, January 02, 2014 2:20 PM
    Moderator
  • Here is the slow burn to how this works.

    Start by not using On Error because it will only hide you mistakes.

    Run this a few times until you understand what is happening.

    Const BIT1 = 2
    folder =  "c:\temp"
    
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFolder = objFSO.GetFolder(folder)
    mask = objFolder.Attributes
    If mask And BIT1 Then
        MsgBox "Folder is hidden: 0x" & Hex(mask)
        ' unhide
        newmask = mask Xor BIT1
        MsgBox "NEWMASK IS: 0x" & Hex(newmask)
        objFolder.Attributes = newmask
    Else
        MsgBox "Folder is NOT hidden: 0x" & Hex(mask)
        newmask = mask Or BIT1
        MsgBox "NEWMASK IS: 0x" & Hex(newmask)
        objFolder.Attributes = newmask
    End If


    ¯\_(ツ)_/¯



    • Edited by jrv Thursday, January 02, 2014 3:59 PM
    Thursday, January 02, 2014 3:55 PM
  • Sorry - I pasted before I had converted all of the pieces. I fixed.

    "Or" and "Xor" are use to twiddle the bits on or off against a mask.  "And" is used to test against a mask.  "BIT1" is the mask for the bit we are interested in.

    This can be generalized as a function that toggles a bit or as a function that toggles a set of bits.


    ¯\_(ツ)_/¯

    Thursday, January 02, 2014 4:02 PM