1

In Windows 11, what is a quick way using only the keyboard to hide or show hidden files in File Explorer?

Windows 10 provided this through keyboard shortcuts for the ribbon, but the ribbon is gone in Windows 11. The new toolbar seems to have little keyboard support, but hopefully there's a workaround. A utility-based solution such as using AutoHotkey would be fine.

Edward Brey
  • 2,005

2 Answers2

2

This works in Windows 10 using AutoHotkey:

Save the file as:

Show Hide Hidden Files Refresh Explorer Windows.ahk

#SingleInstance Force

#IfWinActive ahk_class CabinetWClass ahk_exe explorer.exe

^h:: If (!A_IsAdmin) ; IF NOT Admin { Run, *RunAs "%A_ScriptFullPath%" ; Run script as admin ExitApp ; Exit the current instance running without admin privileges } RegRead, hidden, HKCU, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, Hidden ; Get If Files Hidden Or Shown If hidden contains 1 ; IF Files NOT Hidden { RegWrite, REG_DWORD, HKCU, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, Hidden, 2 ; Hide Hidden Files } Else ; ELSE Files Hidden { RegWrite, REG_DWORD, HKCU, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, Hidden, 1 ; Show Hidden Files } WinGet, windows, List, ahk_exe explorer.exe ; Get List Explorer Windows Loop, %windows% { id := windows%A_Index% ; id WinGetTitle, title, ahk_id %id% ; title WinGetClass, class, ahk_id %id% ; class WinGet, exe, ProcessName, ahk_id %id% ; exe ControlSend, DirectUIHWND2, {F5}, %title% ahk_class %class% ahk_exe %exe% ; Refresh All Explorer Windows } Return

#IfWinActive

  1. #IfWinActive ahk_class CabinetWClass ahk_exe explorer.exe ensures that the script will be run only if Explorer window is active.
  2. ^h:: is the Ctrl+H Hotkey which triggers the code. You can set it to whatever you like.

The script needs to run as admin so that it can write to registry.

  1. A_IsAdmin is a built in variable that returns 1 if current user has admin rights, otherwise returns 0.
  2. It first checks if user is NOT admin (!A_IsAdmin).
  3. If user is not admin, it runs the same script which it gets the full path with the built in variable "%A_ScriptFullPath%". The *RunAs parameter runs the script as admin.
  4. ExitApp exits the current script if it does not have admin rights.
  5. The Run command runs the script again with admin rights, now the script has admin rights, it skips the IF condition and executes code below.
  6. RegRead reads the registry entry that shows if hidden files are hidden or shown. If the value is 1 then it hides the hidden files, otherwise it shows them.
  7. WinGet, windows gets the list of all Explorer windows.
  8. Loop loops through all Explorer windows, gets the title, class and process of each window, and ControlSend, DirectUIHWND2, {F5} refreshes all Explorer windows so that the changes are reflected (files are shown or hidden).
0

ChatGPT solved this issue for me. I can use CTRL+SHIFT+H to toggle it seamlessly.You need PowerToys and it's made by Microsoft. It's very good.

PowerShell Script:

  1. Create a PowerShell script named "ToggleHiddenFiles.ps1" to toggle the visibility of hidden files and folders in Windows 11. Here's the script:

$RegPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" $RegName = "Hidden"

$CurrentValue = Get-ItemProperty -Path $RegPath -Name $RegName | Select-Object -ExpandProperty $RegName

if ($CurrentValue -eq 2) { Set-ItemProperty -Path $RegPath -Name $RegName -Value 1 } else { Set-ItemProperty -Path $RegPath -Name $RegName -Value 2 }

  1. PowerToys Configuration:

• Configure PowerToys to use a keyboard shortcut (Ctrl + Shift + H) to launch PowerShell and run the script. Go to "keyboard manager" and then to "remap a shortcut".

• For PowerShell 7 or later (pwsh.exe):

o Target application: C:\Program Files\PowerShell\7\pwsh.exe

• For Windows PowerShell (powershell.exe):

o Target application: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

  1. Add other fields:

• Action: Run Program

• Arguments: -ExecutionPolicy Bypass -File "PATH\ToggleHiddenFiles.ps1"

• Start in: C:\ (or any other desired directory)

• Elevation: Normal

• If running: Do nothing

• Visibility: Hidden

For "PATH" use the path to the ps1 script. Done. You should be able to toggle hidden files in explorer.

Thank you ChatGPT.