Enable/disable the "Show hidden files" setting from the command line
In Windows Explorer, the setting Show hidden files, folders and drives can be enabled and disabled under Organise > Folder and search options > View
.
Is there another, quicker way to enable/disable this setting? Something via the command line would be ideal, but I'm open to all suggestions that are quicker or less cumbersome.
These settings are in the Registry at this key:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced
To show hidden items, set Hidden
to 1 (to hide them, set it to 2). To show system/super-hidden items, set ShowSuperHidden
to 1 (0 to hide). Since we're fiddling with the Registry directly, Explorer has to be restarted.
To accomplish all of that and enable viewing of everything, you can use these batch commands:
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
powershell -c gps 'explorer' ^| stop-process
If you prefer to avoid PowerShell, this should also work to kill Explorer:
taskkill /im explorer.exe /f
If Explorer doesn't automatically relaunch on your system, simply run explorer
to get your taskbar back.
I decided to take the keys and commands that Ben supplied and write a single batch file that toggles both the Hidden
and ShowSuperHidden
values on or off together.
Toggling Hidden/Super-Hidden Files with a Batch File
You can download ToggleHidden.bat here, but if you'd prefer to copy the script into a .bat
or .cmd
file yourself, here's the source code:
@echo off
REG QUERY "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /v "Hidden" | Find "0x0"
If %ERRORLEVEL% == 0 goto show
IF %ERRORLEVEL% == 1 goto hide
goto :error
:show
REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /v Hidden /t REG_DWORD /f /d 1 > NUL
REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /v ShowSuperHidden /t REG_DWORD /f /d 1
goto restart
:hide
REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /v Hidden /t REG_DWORD /f /d 0 > NUl
REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /v ShowSuperHidden /t REG_DWORD /f /d 0
goto restart
:error
echo There was an error! Check the script.
pause
goto :eof
:restart
taskkill /f /im explorer.exe
start explorer
A breakdown of what the script does: it queries the data of the Hidden
value; if it's off, it toggles both it and ShowSuperHidden
on. If it's already on, it toggles both it and ShowSuperHidden
off. I decided to design the script in this way because it's rare that I personally need to see hidden files without also seeing system files, but you can change this behaviour if you prefer.1
After either enabling or disabling these registry values, the script then kills and restarts the Windows Explorer explorer process. If, for some reason, the value of Hidden
can't be determined by the query
command then the script breaks and echoes an error before exiting.
Mapping the Batch File to a Hotkey
To satisfy my criteria for maximum convenience, I placed the newly-created ToggleHidden.bat
file somewhere on my computer and used AutoHotKey to map a hotkey combination to run it. I did this by adding the following to my existing AHK script:
Ctrl & H::
Run PATH\TO\FILE
Return
I used AutoHotKey here because I already use it for similar purposes and find it the more useful method of assigning hotkeys to run my programs, but if you'd rather not have to install AHK for the purpose of this step, you can also use this native Windows method for assigning hotkeys to a program.
I can now use the hotkey combination Ctrl+H to hide and quickly show or hide hidden/system files at my convenience... and it works beautifully, if I do say so myself.
1If you do plan to go down this route, it's worth noting that, in the Windows ecosystem, superhidden files/folders act as a subset of hidden files/folders.
What this means when it concerns these two registry values is that you can enable the Hidden
value without enabling ShowSuperHidden
, but you can't enable ShowSuperHidden
without enabling Hidden
; doing so will show you only normal items, because Windows considers superhidden items a type of hidden item, and if hidden items are hidden, so are superhidden items. To put it simply: if you're planning to turn on ShowSuperHidden
, you need to make sure you turn on Hidden
with it.
The show hidden folder option is specifically something that's part of Explorer.
Although in the commandline, you can use the attrib
or dir /ah
commands to view hidden files, you cannot control the hidden setting from commandline unless you go through quite some length first. Essentially this setting is stored in the registry, and you can modify the registry from commandline. But it'll be far more cumbersome to go this route than to quickly change the setting on explorer.
If this is something you are going to do frequently, finding the setting in the registry and storing it to a .reg file would be quicker, because then you can double click the two .reg files to enable and disable it.
Unfortunately, I don't know where in the registry it is located. I only know that it's in the HKCU hive, but not where exactly.
If you upgrade to windows 10, this setting can be found directly from the view tab.