39

I often need to toggle between show/hide hidden files in my PC. I have been doing it the usual way,

  • Click Organize in an Explorer window.
  • Select Folder and search options.
  • Switch to View tab.
  • Toggle between Show/Hide Hidden files.

This method is so lengthy and I am tired of it.

I would like to toggle between them from the command line (cmd). Is there any way to achieve this?

Also, a way to toggle between Show/Hide System Files from the command line would be great.

Steven
  • 28,386
RogUE
  • 3,831

9 Answers9

40

Hidden files, folders or drives:

Add (or overwrite /f) the value Hidden to the registry key: HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced.

Show:

reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /v Hidden /t REG_DWORD /d 1 /f

Don't show:

reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /v Hidden /t REG_DWORD /d 2 /f

ToggleHiddenFiles.bat

REG QUERY "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /v Hidden | Find "0x2"
IF %ERRORLEVEL% == 1 goto turnoff
If %ERRORLEVEL% == 0 goto turnon

goto end
:turnon
REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /v Hidden /t REG_DWORD /d 1 /f
goto end

:turnoff
REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /v Hidden /t REG_DWORD /d 2 /f
goto end

:end

Hide protected operating system files (Recommended)

Checked:

reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /v ShowSuperHidden /t REG_DWORD /d 0 /f

Unchecked:

reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /v ShowSuperHidden /t REG_DWORD /d 1 /f

ToggleSystemFiles.bat

REG QUERY "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /v ShowSuperHidden | Find "0x0"
IF %ERRORLEVEL% == 1 goto turnoff
If %ERRORLEVEL% == 0 goto turnon

goto end
:turnon
REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /v ShowSuperHidden /t REG_DWORD /d 1 /f
goto end

:turnoff
REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /v ShowSuperHidden /t REG_DWORD /d 0 /f
goto end

:end

Notes: Changes take place immediately. The program reg requires admin privileges, so run the batch files as administrator.

Steven
  • 28,386
4

The property to show/hide hidden files is managed in the registry, so you would simply need a .reg file that simply toggles this property. Here is how you do it through registry:

  • Type “regedit“, then press “Enter“.
  • Navigate to the following location: HKEY_CURRENT_USER --> Software --> Microsoft --> Windows --> CurrentVersion --> Explorer --> Advanced
  • Set the value for “Hidden” to “1” to show hidden files, folders, and drives.
  • Set the value to “2” to not show hidden files, folders, and drives.
  • Set the value for “ShowSuperHidden” to “1” to show protected operating system files. Set the value to “2” to not show protected operating system files.

If you give me a bit of time, I will write the REG file and post it here. Edit: Steven seems to have posted an example script, so I won't build one.

1

I know you arent using it but its worth considering the upgrade. The process in Windows 10 is: Alt + V H H

You need more keystrokes to open the command prompt in Windows 7.

1

Although not a command line function, here's a method on how to quickly open the window: Show hidden files and folders.

Caution: Review source information in Part 1 concerning Vista before proceeding.

Part 1: Create a folder that contains the object 'Show hidden files and folders'.

Part 2: Create a desktop shortcut of 'Show hidden files and folders'.

Part 3: Open the window for 'Show hidden files and folder'

After you have completed all 3 parts you will have a keyboard shortcut for quick access to the window for 'Show hidden files and folders'.

Part 1

  1. Right click a blank area of the desktop
  2. Click New
  3. Click Folder
  4. Name the folder: How-To Geek.{ED7BA470-8E54-465E-825C-99712043E01C}

Source: http://www.howtogeek.com/howto/8711/stupid-geek-tricks-enable-the-secret-how-to-geek-mode-in-windows/

Part 2:

  1. Open the How-To Geek folder you just created
  2. Click the arrow next to File Explorer Options if it's not already expanded
  3. Right click and drag to the desktop 'Show hidden files and folders'
  4. Click create shortcut here

Note: In this particular situation you could left click and drag, but it's always good practice to right click and drag to ensure you are performing the intended function, and because you can also click cancel if needed.

Part 3:

  1. Right click the shortcut folder on the desktop 'Show hidden files and folders'
  2. Click Properties
  3. On the Shortcut tab click in the Shortcut Key field
  4. Press something like Ctrl + Alt + T
  5. Click OK
  6. Press Ctrl + Alt + T and the 'Show hidden files and folders' will open
0

A possibly more convenient way to accomplish this with minimal effort is through adding a context menu item, to do this:

  1. Create a new simple text document somewhere and name it "togglehidden.reg"
  2. Open it with notepad and paste the following:

    Windows Registry Editor Version 5.00
    
    [HKEY_CLASSES_ROOT\Folder\shell\Windows.ShowHiddenFiles]
    "CommandStateSync"=""
    "Description"="@shell32.dll,-37573"
    "ExplorerCommandHandler"="{f7300245-1f4b-41ba-8948-6fd392064494}"
    "MUIVerb"="@shell32.dll,-37572"
    
    
    [HKEY_CLASSES_ROOT\Directory\Background\shell\Windows.ShowHiddenFiles]
    "CommandStateSync"=""
    "Description"="@shell32.dll,-37573"
    "ExplorerCommandHandler"="{f7300245-1f4b-41ba-8948-6fd392064494}"
    "MUIVerb"="@shell32.dll,-37572"
    
  3. save and close.

  4. double click your new reg file, accept prompts to install it and you're done.

This is what you should get: Hidden Toggle

Source: https://winaero.com/blog/hidden-items-context-menu-windows-10/

0

Thanks to Steven's reply, I could wrote software that toggles this (and refresh open explorer windows) with a single click: Link

Edit:

When the application is opened, it gets a value from the registry key (Hidden) here: HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced.

Depending on the value, a hidden command prompt to change the value is executed. Thereafter every open windows explorer window is refreshed and hidden files/folders is hidden/shown.

It is available for vieweing in the source.

Ian N
  • 1
0

My OS is Windows 8.1 Pro 64-bit. I was interested in a command line to show/hide protected files. Using the reg keys in batch files, it worked well from hidden to show, but not reversely. Digging the registry, I noticed that a key was not immediately updated, requesting a restart of the computer. Its location is HKEY_USERS\S-1-5-21-445602408-3241513752-1080421046-1001\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced. But as Explorer parameters are involved, I had the idea to close and restart it. It works now perfectly.

Here are my two batch files:
Hide:

@echo off
Reg add Hkcu\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced /v ShowSuperHidden /t Reg_Dword /d 0 /f > nul
Taskkill /Im Explorer.exe > nul & Explorer =
Cls & exit

Show:

@echo off
Reg add Hkcu\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced /v ShowSuperHidden /t Reg_Dword /d 1 /f > nul
Taskkill /Im Explorer.exe > nul & Explorer =
Cls & exit

They will open "My PC" when applied. As previously said, they must be run as administrator, either in DOS mode in the System32 folder, or elsewhere from a right click on their names. Hope this will help if some of yours encounter issues similar to mine.

Ji Pé
  • 1
0

To enable "Show hidden files" in Windows explorer, run the following in powershell:

New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" -Name "Hidden" -Value 1 -PropertyType DWORD -Force

Then, to make this change take effect, either reboot/log out and back in or optionally, restart explorer by running:

taskkill /F /IM explorer.exe
explorer.exe
0

I combined them into a single batch script and while the registry value does update, the values displayed in File Explorer Options -->View did not change, even if running as administrator.

Testing revealed that an Explorer restart is truly needed, at least under W10 Pro x64, which makes no sense given that REG values are supposubly ;) updated immediately. But I did not need to run the batch file as administrator.

Here's my working code...

REG QUERY "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /v Hidden | Find "0x2"

IF %ERRORLEVEL% == 1 goto turnoff If %ERRORLEVEL% == 0 goto turnon

goto end ::show hidden and system files :turnon REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /v Hidden /t REG_DWORD /d 1 /f REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /v ShowSuperHidden /t REG_DWORD /d 1 /f goto end

::hide hidden and system files :turnoff REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /v Hidden /t REG_DWORD /d 2 /f REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /v ShowSuperHidden /t REG_DWORD /d 2 /f goto end

:end taskkill /f /im explorer.exe start explorer