Advertisement
Najeebsk

SEARCH2.ahk

Feb 21st, 2023
1,014
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*   INFO
  2.    File Search Engine
  3.    Written by: Najeeb Shah Khan (najeebshahkhan@gmail.com)
  4.    Last Modified: 2-22-2023
  5. */
  6. #NoEnv
  7. #SingleInstance, Force
  8. SetBatchLines, -1
  9. ;#NoTrayIcon
  10. SetWorkingDir %A_ScriptDir%  
  11. ;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  12. Gui -Caption +ToolWindow +Border +LastFound +AlwaysOnTop -Border +hWndhGUI
  13. CustomColor = 884488
  14. Gui, Color, %CustomColor%
  15. Gui,Font,S14 CGreen Bold,Verdana ;Calibri
  16. ;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  17. Hotkey, ^Esc, Quit
  18. GetFile()
  19. {
  20.    Global FileName ;Allows the program to use the variable (FileName) outside this loop
  21.    Global FileDir
  22.    RowNumber = 0  ;Loop starts search at top of ListView control.
  23.    Loop
  24.    {
  25.       RowNumber := LV_GetNext(RowNumber)  ;Resume search at next row.
  26.       if not RowNumber  ;Above is zero, so no more selected rows.
  27.          break
  28.       LV_GetText(FileName, RowNumber,1)
  29.       LV_GetText(FileDir, RowNumber,2)
  30.    }
  31. }
  32.  
  33. ;Adding Menu Item Section
  34. Menu, ListMenu, add,Run,RunProgram
  35. Menu, ListMenu, add,Edit With Notepad,EditProgram
  36. Menu, ListMenu, add,Open containing folder,OpenFolder
  37. Menu, ListMenu, add,Properties,GetProperties
  38. Menu, ListMenu, add,Delete this file,DeleteFile
  39. Menu, ListMenu, add,Re-Start Search,Re-Start
  40. Gui, Add, Button, hWndhButton2 x5 y5 w0 h0 gGuiMove,
  41. Gui, add, text,x10 y14,Search Where?:
  42. Gui, Add, DropDownList,x190 y10 w80 vLocation, DIR||C|D|E|F|G|H|I|J|K|L|Y|Z
  43. Gui, add, text,x280 y14,Search File Name:
  44. Gui, add, edit,x485 y10 w120 vName
  45. Gui, add, text,x610 y14,File Extension:
  46. Gui, Add, DropDownList,x780 y10 w80 vExtension gUnPause, EXT||mp4||mp3|aac|flac|aif|aiff|m4a|flv|mpg|vob|mvk|wmv|avi|m3u|m3u8|xml|jpg|jpge|bmp|png|gif|ico|txt|bat|vbs|ahk|au3|sh|ini|ls|doc|cmd|js|pdf|fm|exe|ink|cpl|dll|rar|zip|7z|iso|daa|bin|cue|img|
  47. Gui, Show, x0 y30 w900 h60 Center, Search
  48. WinSet, Region, 0-0 W900 H60 R20-20,
  49. WinMove, 0, 0
  50. OnMessage( 0x200, "WM_MOUSEMOVE")
  51. Pause
  52. Gui, destroy
  53.  
  54. Gui, Add, ListView, r20 w700 vFileList gListViewAct sort, Name|File Path
  55. ;GuiControl, FileList
  56. Gui, add, Text,vText1 w200
  57. Gui, add, Button, vBreakSearch gBreakSearch,Break Search
  58. Gui, show,,Search Found: 0 files.
  59. Name = *%Name%* ;Finds files with a name containing those characters (and others surrounding it)
  60. Loop, %Location%:\%Name%%Extension%,1,1
  61. {
  62.    GuiControl,,Text1,%a_loopfilename% ;Tells name of current found file
  63.    WinSetTitle,Search Found:,,Search Found: %a_index% files. ;Title tells # of files found
  64.    NumberFound = %a_index%
  65.    LV_Add("", A_LoopFileName, A_LoopFileDir)
  66.    LV_ModifyCol()
  67.    If Brk=1   ;Check if it user presses break button
  68.    {
  69.       Break
  70.    }
  71. }
  72. Gui, +Resize
  73. GuiControl, hide,Text1
  74. GuiControl, hide,BreakSearch
  75. GResize=1
  76. Gui, show, AutoSize,Search Found: %NumberFound% files.
  77.  
  78. ListViewAct:
  79. if A_GuiEvent = DoubleClick
  80. {
  81.    GetFile()
  82.    Run %FileDir%\%FileName%
  83. }
  84. return
  85.  
  86. GuiContextMenu:
  87. If A_GuiControl <>FileList ;If cursor is inside 'FileList' (ListView control)
  88.    return
  89. Menu, ListMenu,Show,%A_GuiX%,%A_GuiY%
  90. return
  91.  
  92. ;Here are the right-click menu actions
  93. RunProgram:
  94.   GetFile()
  95.    Run, %FileDir%\%FileName%
  96. return
  97.  
  98. EditProgram:
  99.   GetFile()
  100.    Run, Notepad.exe "%FileDir%\%FileName%"
  101. return
  102.  
  103. OpenFolder:
  104.   GetFile()
  105.    Run %FileDir%
  106. return
  107.  
  108. GetProperties:
  109.   GetFile()
  110.    Run properties %FileDir%\%FileName%
  111. return
  112.  
  113. DeleteFile:
  114.   If LV_GetCount("Selected") > 1 ;Checks if more than one row is selected
  115.       {
  116.          MsgBox,,OOPS!,You cannot have more than one row selected.`nPlease select only one row, then try again.
  117.       return
  118.       }
  119.    else
  120.       {
  121.          GetFile()    
  122.          MsgBox, 262196, Alert!, Do you really want to delete "%FileName%"?
  123.          IfMsgBox Yes
  124.             {
  125.                FileDelete %FileDir%\%FileName%
  126.                MsgBox,262144,Delete,The file: "%FileName%" has been deleted!
  127.                LV_Delete(LV_GetNext()) ;This one goes to my dad. It deletes the row returned by the 'Get Next' check.
  128.             }
  129.       }
  130.    return
  131.  
  132. Re-Start:
  133. F5::      ;F5 key also re-starts
  134.    IfWinActive,Search
  135.    Reload
  136. return
  137. ;End of the right-click actions
  138.  
  139. ~Enter::
  140. ~NumpadEnter::
  141. UnPause:
  142. IfWinActive,Search,Search Where?
  143. {
  144.    GuiControlGet,Location
  145.    GuiControlGet,Name
  146.    GuiControlGet,Extension
  147.    If %Location%
  148.    {
  149.       If %Extension%
  150.       {
  151.          Pause, Off
  152.          return
  153.       }
  154.       Else   ;Extension field isn't filled in
  155.       {
  156.          Pause, Off
  157.          Extension = *   ;Wildcard for extensions
  158.          return
  159.       }
  160.    }
  161.    Else   ;Location field isn't filled in
  162.    {
  163.       MsgBox,48,Error,Please fill in 'Search Where'
  164.    }
  165.    return
  166. }
  167. IfWinActive,Search Found:,Break Search
  168. {
  169.    GetFile()
  170.    Run, %FileDir%\%FileName%
  171. }
  172. return
  173.  
  174. ;;;;;Help Section;;;;;
  175. ~F1::
  176. IfWinActive,Search
  177. {
  178.    Gui, 2:+owner1
  179.    Gui, 2:Add, Edit,+ReadOnly w250 r20,This search engine was created by:`nNajeeb Shah Khan (najeebshahkhan@gmail.com).`n---(Yes, I did rely heavily on the help file for ListView commands.)`n`nDirections:`n---------------`nType the LETTER of the drive to search.`nExample: type "C" (without quotes) to search C:\`n`nKeys:`n---------------`nF1:     Help`n`nF5:     Restart Script`n`nPause Key:  Pause/UnPause the script`n`nCtrl+Esc:   Emergency Exit`n`nHints:`n---------------`nIn the ListView, you can right-click for file options.
  180.    Gui, 2:Add, Button, Default g2GuiClose, Go Back
  181.    Gui, 2:Show,, File Search Help
  182.    ControlFocus, Go Back, File Search Help   ;Put focus on the 'Go Back' button
  183.    Pause, on   ;Pause the search
  184. }
  185. return
  186. ;;;;;End of Help Section;;;;;
  187.  
  188.  
  189.  
  190.  
  191. GuiSize:
  192. If GResize=1   ;Check if I allowed resizing for the active Gui
  193. {
  194.    GuiControl, Move, FileList, % "W" . (A_GuiWidth-20) . "H" . (A_GuiHeight-20)   ;Modify the ListView
  195. }
  196. return
  197.  
  198. Pause:: ;User pressed pause/break key, toggle pause
  199. Pause,Toggle
  200. IfWinActive,Search   ;Check if search window is active
  201.    return         ;It is active, so continue
  202. Else
  203.    Pause, on      ;Search window isn't active, so re-pause the script
  204. return
  205.  
  206. BreakSearch:
  207. Brk=1   ;Ready to break
  208. return
  209.  
  210. ;Gui 2 (Help Window) Exit Section
  211. 2GuiClose:
  212. 2GuiEscape:
  213. Gui, destroy
  214. Pause, off
  215. return
  216.  
  217. ;Primary Gui Exit Section
  218. GuiClose:
  219. GuiEscape:
  220. Quit:
  221. ExitApp
  222. ;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  223. GuiMove:
  224.  PostMessage, 0xA1, 2,,, NAJEEB SCRIPT BOOK
  225. Return
  226. ;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  227. WM_MOUSEMOVE(wparam, lparam, msg, hwnd)
  228. {
  229.     if wparam = 1 ; LButton
  230.         PostMessage, 0xA1, 2,,, A ; WM_NCLBUTTONDOWN
  231. }
  232. ;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-END-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  233.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement