Hi.
I have added the ability to search for files through regular expressions (RegEx), as shown in the video. Since I don't know much about expressions I have used a simple example (through the interface of the program "Everything" I am learning to use them, since either no search comes out or the program puts in bold the part of the text that matches the expression). I have set by default, in the final GUI, that the script does not do anything, because it has already happened to me that when I set it to open the files found in the explorer, the system collapses as soon as there are many (I had to restart).
I have also added the ability to open the generated .txt file to give the option of saving it with another name, and because if there are many files, they are not seen in the small final GUI. Puts the number of files found and displays the first two lines. The file number already gives us a clue as to what we should do, whether to open it or not do anything, and open the text file or paste it to the clipboard.
Code: Select all
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory
;EnvSet, SD, %A_ScriptDir%
GetKeyState, state, Ctrl
if (state = "D")
{
ClipBoard:=""
}
;Send ^c ;optional. If you just want to select the text and have the script copy it to the clipboard, remove the semicolon.
DetectHiddenWindows, Off
Event=0
if not WinExist("Everything")
{
Run, d:\Utilidades\Everything\Everything.exe -startup
}
If !Clipboard
{
Gosub, SearchGUI
}
Else
{
TempClip:= Clipboard
Gosub, Rutine
}
Return
SearchGUI:
TempClip:=Clipboard
xposUtil := Floor((A_ScreenWidth/2)-450)
yposUtil := Floor((A_ScreenHeight/2)-200)
Gui, Search:+HwndGuiID
Gui, Search: Font, S9 Bold, Verdana
Gui, Search: Add, Edit, x10 y16 w230 h20 vMySearch, Enter your Search
Gui, Search: Add, Button, x250 y16 w65 h20 GSearch, Search
Gui, Search: Add, CheckBox, x10 y46 w300 h20 vRegEx, Use RegEx Search
Gui, Search: Show, x%xposUtil% y%yposUtil% h80 w330, GUI
;Gui, Search: Show, x%xposUtil% y%yposUtil% h56 w330, GUI
Return
#If WinActive("ahk_id " GuiID)
Enter::
NumPadEnter::
Search:
Gui Search: Submit
TempClip:=MySearch
Gui Search: Destroy
Gosub, Rutine
Return
Rutine:
FileDelete, h:\File_Temp.txt
If RegEx=1
{
RunEverything:= "d:\Utilidades\Everything\es.exe -r """ TempClip """ > h:\File_Temp.txt"
}
Else
{
TempClip:= RegexReplace(TempClip, "[\-\_\s+]", "*")
RunEverything:= "d:\Utilidades\Everything\es.exe """ TempClip """ > h:\File_Temp.txt"
}
FileAppend, %RunEverything%, h:\Everything.bat
RunWait, h:\Everything.bat ,,hide
FileRead, OutputEnd, h:\File_Temp.txt
FileDelete, h:\Everything.bat
;FileDelete, h:\File_Temp.txt
If !OutputEnd
{
Gosub, NotFound
}
Else
{
Gosub, GuiControl
}
Return
GuiControl:
Loop, Read, h:\File_Temp.txt
NumLines := A_Index
SoundPlay, *64
Gui, Control: Add, GroupBox, x22 y60 w340 h140, Options
Gui, Control: Add, Radio, x32 y80 w300 h20 vDirectory, Open the Container Directory
Gui, Control: Add, Radio, x32 y100 w300 h20 vOpenFile, Open the file
Gui, Control: Add, Radio, x32 y120 w300 h20 vFileAndDir, Open the File and Open the Directory
Gui, Control: Add, Radio, x32 y140 w300 h20 vNothing Checked, Do Nothing
Gui, Control: Add, CheckBox, x32 y170 w100 h20 vCopyClip, Copy to Clipboard
Gui, Control: Add, CheckBox, x150 y170 w100 h20 vTxtOpen, Open file List
Gui, Control: Add, Button, x30 y210 w100 h30 gCancel, Cancel
Gui, Control: Add, Button, x252 y210 w100 h30 gOptions, OK
;Gui, Control: Font, S9 Bold, Verdana
Gui, Control: Add, Text, x22 y16 w340 h40 , %NumLines% file(s) exists in %OutputEnd%
Gui, Control: Show, x910 y416 h260 w384, GUI Control
Return
Options:
Gui, Control: Submit
If Directory
{
If (NumLines<>1)
{
Loop, %NumLines%
{
FileReadLine, VarOut, h:\File_Temp.txt, %A_Index%
StringGetPos, pos, VarOut, \, r1
length := pos+1
StringLeft, OutText, VarOut, %length%
Run, explorer %OutText%
}
}
Else
{
StringGetPos, pos, OutputEnd, \, r1
length := pos+1
StringLeft, OutText, OutputEnd, %length%
Run, explorer %OutText%
}
If CopyClip=1
{
Clipboard:= OutputEnd
}
If TxtOpen=1
{
Run, h:\File_Temp.txt
}
ExitApp
}
If OpenFile
{
If (NumLines<>1)
{
Loop, %NumLines%
{
FileReadLine, VarOut, h:\File_Temp.txt, %A_Index%
Run, Explorer %VarOut%
}
}
Else
{
Run, Explorer %OutputEnd%
}
If CopyClip=1
{
Clipboard:= OutputEnd
}
If TxtOpen=1
{
Run, h:\File_Temp.txt
}
ExitApp
}
If FileAndDir
{
If (NumLines<>1)
{
Loop, %NumLines%
{
FileReadLine, VarOut, h:\File_Temp.txt, %A_Index%
Run, Explorer %VarOut%
StringGetPos, pos, VarOut, \, r1
length := pos+1
StringLeft, OutText, VarOut, %length%
Run, Explorer %OutText%
}
}
Else
{
Run, Explorer %OutputEnd%
StringGetPos, pos, OutputEnd, \, r1
length := pos+1
StringLeft, OutText, OutputEnd, %length%
Run, explorer %OutText%
}
If CopyClip=1
{
Clipboard:= OutputEnd
}
If TxtOpen=1
{
Run, h:\File_Temp.txt
}
ExitApp
}
If Nothing
If CopyClip=1
{
Clipboard:= OutputEnd
}
If TxtOpen=1
{
Run, h:\File_Temp.txt
}
ExitApp
NotFound:
SoundPlay, *64
MsgBox, The file does not exist on the computer.
ExitApp
Cancel:
ExitApp