AutoHotkey Community

It is currently May 26th, 2012, 1:56 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: December 31st, 2007, 10:00 pm 
Offline

Joined: November 17th, 2007, 8:30 pm
Posts: 16
Hi

The problem with the Windows built in find and replace is that it takes too long to find the text in files and it does not support Regex.

I wrote a fairly simple script which can be used to search a directory tree using Visual Studio. The aim is that you would have a right click a folder in Explorer and then click on "Find using Vs2005" and this would drop you into visual studio and the text box contains the directory you selected.

It is a simple script, but I hope you find it useful:

Code:
#SingleInstance force
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
SetTitleMatchMode, 2 ; A window's title can contain WinTitle anywhere inside it to be a match

Run, C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\devenv.exe ; The program we use to search files with
Loop, 50 ; Spend a maximum of 5,000ms = 5sec for Visual Studio to open for this purpose.
{
   IfWinExist Start Page - Microsoft Visual Studio ; It has finally loaded!
   {
      WinActivate, Start Page - Microsoft Visual Studio ; Activate the window
      Send, ^+f   ; Open the Find in Files dialog using this shortcut
      Sleep, 100  ; Sleep long enough so the find dialog can initialise
      if 0 > 0    ; If there is at least one argument
      {
         StringReplace, 1, 1, ",, All ; Remove trailing instances of quote " mark
         ControlSetText, Edit3, %1%, Find and Replace ; Set the Directory Text box to the argument
      }
      ControlFocus, Edit1, Find and Replace ; Set the focus to the string search box
      Break ; Break if we so all the above.
   }
   Sleep, 100


ExitApp

We also need need a registry entry which adds the context sensitive menu to the windows explorer:

Code:
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell\FindVs2005]
@="Find using Vs2005"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell\FindVs2005\command]
@="\"C:\\Program Files\\AutoHotkey\\AutoHotkey.exe\" \"C:\\FindInFiles.ahk\" \"%L\""

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Drive\shell\FindVs2005]
@="Find using Vs2005"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Drive\shell\FindVs2005\command]
@="\"C:\\Program Files\\AutoHotkey\\AutoHotkey.exe\" \"C:\\FindInFiles.ahk\" \"%L\""

Obviously replace C:\\FindInFiles.ahk to the path of the script.

-Tahir


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], Exabot [Bot] and 17 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