AutoHotkey Community

It is currently May 27th, 2012, 10:31 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: October 23rd, 2007, 8:05 pm 
Offline

Joined: May 24th, 2007, 3:45 am
Posts: 1121
For a long time I've always had Windows set to show hidden files, I imagine many technical-minded people do. There are a lot of hidden files that I need to get to sometimes, like the Application Data folder. But there are also a lot of files that really should be hidden most of the time, like all those $NtUninstallXXXXXXX$ folders in C:\Windows or all the Desktop.ini files scattered around. They're just unneeded clutter on the screen.

So I wanted to come up with a way to toggle them on and off easier, and also have some way of knowing that there are hidden files in a given folder without having to see the full list of them.

Here's what I came up with:

Code:
#SingleInstance Force
#NoEnv
#Persistent
SendMode Input

; Hide & See By ManaUser can
;
; * Toggle visibility of hidden files in Windows Explorer.
; * Report existance of hidden files when they are not show.
; * Temportarily show hidden files in current folder.
;
; You must make the address bar visible in Windows Explorer for this to work.
; Right-click icon to access a context menu.
; Double-Click or use Win+S hotkey to see hidden files temportarily.

Ignore = desktop.ini|thumbs.db|Recycled|RECYCLER

GroupAdd Explorer, ahk_class ExploreWClass
GroupAdd Explorer, ahk_class CabinetWClass

Menu TRAY, NoStandard
Menu TRAY, Add, &See Files Now, SeeHiddenFiles
Menu TRAY, Default, &See Files Now
Menu TRAY, Add, &Always Show, AlwaysShow
Menu TRAY, Add, &Quit, Quit

SetTimer Refresh, 250

Refresh:

If (CheckReg() = 1)
{
   ;Menu TRAY, Icon, icons\Gate-Show.ico   
   Menu TRAY, Icon, SHELL32.DLL, 127
   Menu TRAY, Disable, &See Files Now
   Menu TRAY, Check, &Always Show
}
Else
{
   ;Menu TRAY, Icon, icons\Gate.ico
   Menu TRAY, Icon, SHELL32.DLL, 46
   Menu TRAY, Enable, &See Files Now
   Menu TRAY, UnCheck, &Always Show
}

IfWinActive ahk_group Explorer
{
   ID := WinExist("A")
   WinGetClass ExplorerWin, A
   ControlGetText CurrentPath, Edit1, ahk_class %ExplorerWin% ;Address bar

   If (CurrentPath = "My Documents") ;Substitute real path for speciial folders
      CurrentPath := A_MyDocuments
   Else If (CurrentPath = "Desktop")
      CurrentPath := A_Desktop
   Else If NOT InStr(CurrentPath, "\")
      Return

   If (CurrentPath != LastPath)
   {
      LastPath := CurrentPath

      UpdateExp(ID)

      HiddenFiles := 0
      Loop, %CurrentPath%\*, 0 ;non-folders
      {
         If InStr(FileExist(A_LoopFileLongPath), "H")
         {
            If NOT RegExMatch(A_LoopFileName, "i)^(" . Ignore . ")$")
            HiddenFiles++
         }
      }
      HiddenFolders := 0
      Loop, %CurrentPath%\*, 2 ;folders only
      {
         If InStr(FileExist(A_LoopFileLongPath), "H")
         {
            If NOT RegExMatch(A_LoopFileName, "i)^(" . Ignore . ")$")
               HiddenFolders++
         }
      }

      If HiddenFolders
      {
         If HiddenFiles
            Message = Files: %HiddenFiles%`r`nFolders: %HiddenFolders%
         Else
            Message = Folders: %HiddenFolders%
      }
      Else
      {
         If HiddenFiles
            Message = Files: %HiddenFiles%
         Else
            Message = No Hidden Files
      }

      Menu TRAY, Tip, %Message%
      If (Message = "No Hidden Files")
         SetTimer KillTrayTip, -1
      else
      {
         TrayTip, , %Message%
         SetTimer KillTrayTip, -3000
      }
   }
}
Return

KillTrayTip:
TrayTip
Return

SeeHiddenFiles:
#IfWinActive ahk_group Explorer
#s:: ;WinKey + S Shortcut
#IfWinActive

If CheckReg() = 1
   Return

WinActivate ahk_id %ID%

SetReg(1)
UpdateExp(ID)
Sleep 250
SetReg(2)
Return

AlwaysShow:
If CheckReg() = 1
   SetReg(2)
Else
   SetReg(1)
UpdateExp(ID)
Goto Refresh
Return

Quit:
ExitApp
Return

UpdateExp(ID)
{
   If (A_OSType = "WIN32_WINDOWS")
      PostMessage, 0x111, 41504,,, ahk_id %ID%
   else
      PostMessage, 0x111, 28931,,, ahk_id %ID%
}

CheckReg()
{
   RegRead, Status, HKCU, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, Hidden
   Return Status
}

SetReg(Status)
{
   RegWrite, REG_DWORD, HKCU, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, Hidden, %Status%
}


I already have a few improvements in mind, such as a built-in way to edit the ignore list, and support for alternate methods of checking the current folder. But I'd like to hear what the rest of you think.

Do you like this idea at all? If so how could it be improved? In terms of features, interface or efficiency.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 23rd, 2007, 9:35 pm 
Offline

Joined: February 24th, 2007, 6:02 pm
Posts: 175
Location: Budapest, Hungary
Nice.
It is especially useful if somebody uses Explorer frequently.
I almost never use it because I am more productive with Total Commander which has an ignore list feature for this purpose.

But I have some advice for your scripting:
If you use PostMessage then please write a comment at the end of line with the name of the message constants that you are posting or at least an explanation of the effect what this window message does.

And are you sure that you are checking WIN32_WINDOWS ? I think it should be Windows NT.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 24th, 2007, 3:28 am 
Offline

Joined: May 24th, 2007, 3:45 am
Posts: 1121
You're right that I should have put a comment by the post messages. The function is named UpdateExp, but I suppose that's not very explicit. What it does is cause Explorer to re-display the current folder using the new hidden file settings.

The check for "WIN32_WINDOWS", however, is correct, at least as far as I can tell. (Though I don't have a Win9X box handy to test it.) I'm just going by Skan's Tips N Tricks thread.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 13th, 2008, 7:58 am 
very usefull!


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Google [Bot], specter333 and 12 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group