Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Toggle Hidden Files


  • Please log in to reply
38 replies to this topic
r0lZ
  • Members
  • 192 posts
  • Last active: Feb 11 2012 11:19 PM
  • Joined: 21 Apr 2007
Hum, I don't like the methods that open a window to manipulate it. It's dangerous, subject to change from OS to OS, and inelegant.

My method is much more clean, and is much simpler. If the code is longer, it's only because my script offers to toggle the Show Hidden Files AND Show System Files independently, and most of the code is needed only for the tray menu and the command line arguments. In fact, the method is entirely contained in the two functions ShowHiddenFiles(mode) and RefreshExplorerWindows(). Approximately 20 lines of code. The rest is pure cosmetics, that you can easily remove if you just want to change the Hidden Files mode with a hotkey.
r0lZ

rbrtryn
  • Members
  • 1177 posts
  • Last active: Sep 11 2013 08:04 PM
  • Joined: 22 Jun 2011

Hum, I don't like the methods that open a window to manipulate it.


Point taken, but I don't like directly manipulating the Registry. A mistake doing that can botch up the whole system.

It's dangerous

I don't think there is much risk in sending keys to the folder options dialog.

subject to change from OS to OS


The Registry is also subject to change from OS to OS

and inelegant.

Well, that's a matter of opinion. I prefer the simplest solution that works for the task at hand.

SinTroN
  • Members
  • 26 posts
  • Last active: Mar 28 2012 02:44 AM
  • Joined: 12 Apr 2010
Thank you r0lZ. You made wonderful script! Works correct on Win7 x64 with Autohotkey_L x64

r0lZ
  • Members
  • 192 posts
  • Last active: Feb 11 2012 11:19 PM
  • Joined: 21 Apr 2007

Point taken, but I don't like directly manipulating the Registry. A mistake doing that can botch up the whole system.

That's theoretically right but only when you manipulate critical parts of the registry, such as HKLM. It's not the case here.


It's dangerous

I don't think there is much risk in sending keys to the folder options dialog.

Again, theoretically right, but your script doesn't send the key to the option dialog. It opens it, then send the key. Although it may work fine 999 times/1000, it is not impossible that another window opens just when the key is sent, and that new window will receive it instead ot the option dialog. Sending keys blindly is always dangerous. My script uses ControlSend, so there is no risk to sent the key to another window.

subject to change from OS to OS


The Registry is also subject to change from OS to OS

Right, but your script uses the registry too.

and inelegant.

Well, that's a matter of opinion. I prefer the simplest solution that works for the task at hand.

IMO, the simplest solution is mine. Writing the correct value to the registry is direct, and it will work regardless of the system load and minor GUI changes. Your script is actually using the GUI to write the same value to the registry. One additional step, useless and prone to various problems. Also, I think that opening a window or popup menu just to send it a key doesn't look professional, and in that sense, it's inelegant.

Thank you r0lZ. You made wonderful script! Works correct on Win7 x64 with Autohotkey_L x64

Thanks! :-)
r0lZ

JakeAdriano
  • Members
  • 1 posts
  • Last active: Apr 15 2013 04:36 AM
  • Joined: 14 Apr 2013
Greetings all, this is my first post so I hope it helps!
 
First off, kudos to thinkstorm for the original code. I couldn't get it working correctly on Windows 8 and after reading through the thread I think I have an update that gets the job done.
 
Here's my 2 cents, the simplest version I've had consistent success with:
 

1. I mapped Windows key + h as my toggle key combo, but you can use just about any other key combo you wish

2. I've noticed that it helps if your key combo choice is as-of-yet unused in the respective program
3. In this case WIN+h already activates the Windows "Share charm" but I rarely use it anyway

 
#h::
	WinGetActiveTitle, WinTitle
	WinGetClass, WinClass, %WinTitle%
	
	; 'next line of code stipulates any active Explorer class window i.e. Explorer OR Internet Explorer'
	; 'the following line stipulates any active Explorer window specifically i.e. Explorer windows only, excludes Internet Explorer windows'
	; 'the line after that invokes the View menu tab in the Explorer "Ribbon" with ALT+v (whether the Ribbon is minimized or not)'
	; 'once the View menu tab is active, double tapping the h key toggles Show/hide Hidden items (with the necessary Sleep commands in between)'
	
	If WinClass <> CabinetWClass
		If WinClass <> ExploreWClass
			Return
		Send, !v 
		Sleep, 10
		Send, h
		Sleep, 10
		Send, h
Return

; 'Since this is a simple toggle, pressing WIN+h repeatedly will only toggle back and forth between Showing/hiding Hidden items in the active Explorer window'
 
p.s. - I have the Explorer "Ribbon" showing by default, but I tested with it minimized as well and it seems to work just fine either way.
 
p.p.s. - I tried to comment on and explain each line as best I could, so apologies if my comments seem obvious or redundant.
 
 

 

 

 

 

Hi,
in order to make this work, you first have to go to Windows Explorer and clear the checkbox in 'Tools->Folder Options->View->Advanced Settings' which states 'Hide protected operating system files', so all files would be displayed if you toggle 'hidden files'.
You might have to run the script two times if you start it the first time to get the variable set right....

showHidden=0

#H::
	WinGetActiveTitle, WinTitle
	WinGetClass, WinClass, %WinTitle%
	If WinClass <> CabinetWClass
		If WinClass <> ExploreWClass
			Return
	Send, !T
	Sleep, 100
	Send, o
	WinWaitActive, Folder Options,,5
	if ErrorLevel = 1
		Return
	Send, ^{Tab}
	Sleep, 50
	Send, {Tab}{Tab}
	Sleep, 50
	If showHidden  = 0
	{
		showHidden = 1
		Send, {Down}{Down}{Down}{Down}{Down}{Down}{Down}{Down}{Down}{Down}
	}
	Else
	{
		showHidden = 0
		Send, {Down}{Down}{Down}{Down}{Down}{Down}{Down}{Down}{Down}
	}
	sleep, 50
	Send, {Space}
	Send, {Tab}{Tab}{Enter}
Return
Cheers, Thorsten

 



rbrtryn
  • Members
  • 1177 posts
  • Last active: Sep 11 2013 08:04 PM
  • Joined: 22 Jun 2011

Toggle Hidden Files, System Files and File Extensions

 

(Please ignore my previous post)


My Scripts are written for the latest released version of AutoHotkey.

Need a secure, accessible place to backup your stuff? Use Dropbox!


chaz
  • Members
  • 192 posts
  • Last active: Oct 01 2015 02:42 AM
  • Joined: 26 Mar 2013

Here's my take on this. I didn't wan't an intrusive GUI or a tray icon, so my script toggles the visibility of hidden files with Ctrl+Windows+H and the visibility of both hidden and system files with Shift+Ctrl+Windows+H (you can change these of course) and shows a ToolTip by the cursor showing the state of each. The script refreshes all Explorer windows (inc. the Desktop) automatically without requiring that the Explorer window be active.

 

I recycled and modified some of R01Z's functions.

;===================================================================================
; Toggle visibility of hidden files in Explorer with Ctrl+Windows+H, and
; toggle visibility of both system files and hidden files with Ctrl+Shift+Windows+H.
;===================================================================================

;============AutoExecute============
ToolTipTimeShow := 1000		;Set the time to show the ToolTip.

ControlGet, hwWindow, HWND,, SysListView321, ahk_class Progman
if hwWindow {	; Win XP
	desktopclassname := "Progman"
	explorerlistview := "SysListView321"
} else {	; Win 7+
	desktopclassname := "WorkerW"
	explorerlistview := "DirectUIHWND3"
}
GroupAdd, ExplorerWindowsGroup, ahk_class CabinetWClass
;==========End AutoExecute==========

^#h::		;Toggle visibility of hidden files with Ctrl+Windows+H. Keep system files hidden.
RegRead, HiddenVisible, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, Hidden		;Hidden files: 1 is visible, 2 is hidden.
RegRead, SystemVisible, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, ShowSuperHidden	;System files: 1 is visible, 0 is hidden.
if HiddenVisible = 2		;If hidden files are not visible...
    ShowHiddenFiles(1)			;...show hidden files and hide system (superhidden) files.
else if SystemVisible = 1	;Or if system files are visible...
    ShowHiddenFiles(1)			;...make system files not visible and keep hidden files visible.
else ShowHiddenFiles(0)		;Otherwise hide all.
gosub, ShowToolTip
return

^+#h::		;Toggle visibility of  hidden files and system files with Ctrl+Shift+Windows+H.
RegRead, HiddenVisible, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, Hidden	
RegRead, SystemVisible, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, ShowSuperHidden
if SystemVisible = 0	;If system files are not visible, show both system and hidden files.
  ShowHiddenFiles(2)
else			;Otherwise hide all.
  ShowHiddenFiles(0)
gosub, ShowToolTip
return

ShowToolTip:
ToolTip, Hidden Files: %HiddenFilesState%`nSystem Files: %SystemFilesState%
SetTimer, RemoveToolTip, %ToolTipTimeShow%	;The ToolTipTimeShow variable is in the Autoexecute section at the top of this script.
RefreshExplorerWindows()r
eturn
RemoveToolTip:
SetTimer, RemoveToolTip, Off
ToolTip
return

ShowHiddenFiles(mode) {		;Parameters: 0 hides all, 1 shows only hidden files, 2 shows both hidden and system files.	
global HiddenFilesState, SystemFilesState
    if (mode == 0) {
	RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, Hidden, 2
	RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, ShowSuperHidden, 0	;<<Normally not necessary, but because this script relies on the registry key for the current state, the key needs to be updated every time.
	HiddenFilesState := "Not Visible"
	SystemFilesState := "Not Visible"
    } else if (mode == 1) {
	RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, Hidden, 1
	RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, ShowSuperHidden, 0
	HiddenFilesState := "Visible"
	SystemFilesState := "Not Visible"
    } else {
	RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, Hidden, 1
	RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, ShowSuperHidden, 1
	HiddenFilesState := "Visible"
	SystemFilesState := "Visible"
    }
    sleep, 10
    return
}

RefreshExplorerWindows() {
global desktopclassname, explorerlistview
ControlSend, ahk_parent, {F5}, ahk_class %desktopclassname%		; refresh Desktop
ControlSend, %explorerlistview%, {F5}, ahk_group ExplorerWindowsGroup	; refresh all Explorer windows
ControlSend, DirectUIHWND3, {F5}, ahk_group ExplorerWindowsGroup	; refresh all Explorer windows
}

Find me at the other forum as timeFlies.


No_Speak_Eng
  • Members
  • 6 posts
  • Last active: Oct 25 2013 10:33 AM
  • Joined: 22 Apr 2013
refresh
WinGet, ListId , List, ahk_exe explorer.exe
Loop % ListId
   ControlSend, SysTreeView321, {f5}, % "ahk_id " ListId%A_Index% 
ControlSend, ahk_parent, {f5}, Program Manager ahk_exe explorer.exe
else
for window in ComObjCreate("Shell.Application").Windows
   ControlSend, SysTreeView321, {f5}, % "ahk_id " window.hwnd
ControlSend,, {f5}, Program Manager ahk_exe explorer.exe
example my script
^#h::   ;Toggle visibility of hidden files with Ctrl+Windows+H. Keep system files hidden.
    RegRead, H, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, Hidden  
    RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, ShowSuperHidden, 0
    HiddenFiles(H, (H = 2 ? "" : "System & ") "Hidden files")
    Return
    
^+#h::   ;Toggle visibility of  hidden files and system files with Ctrl+Shift+Windows+H.    
    RegRead, H, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, Hidden  
    RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, ShowSuperHidden, % (H = 2) ? 1 : 0  
    HiddenFiles(H, "System & Hidden files")
    Return    
    
HiddenFiles(H, T) {
    RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, Hidden, % (H = 2) ? 1 : 2 
    for window in ComObjCreate("Shell.Application").Windows
        ControlSend, SysTreeView321, {f5}, % "ahk_id " window.hwnd
    ControlSend,, {f5}, Program Manager ahk_exe explorer.exe
    TrayTip, % T, % (H = 2) ? "Show" : "Hide", 1, 1
} 


Skrell
  • Members
  • 384 posts
  • Last active: Jul 07 2016 05:03 PM
  • Joined: 23 Aug 2011

Does this last version work with Win8?