-
Notifications
You must be signed in to change notification settings - Fork 1
/
Find Files RegEx.ahk
431 lines (398 loc) · 11.8 KB
/
Find Files RegEx.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
#NoEnv
#SingleInstance, Force
SplitPath, A_WinDir,,,,, SysDrive
SysDrive .= "\"
SplitPath, A_ScriptFullPath,, Path,, File
iniFile := Path "\" File ".ini"
ToDoList =
(
Wish list:
• Commandline version
• "Basic" (non-RegEx) search history
• Search within results
• Rewrite/Cleanup/Make functions
• Total size of selected files
• Selected Properties
)
; Declare variables as Arrays (initialize to 10 empty strings)
PathArray := ["","","","","","","","","",""]
RegExArray := ["","","","","","","","","",""]
Gosub ReadHistory
Menu, Tray, Icon, %A_WinDir%\system32\SHELL32.dll, 210
hIcon := DllCall( "LoadImage", UInt,0, Str, Ico, UInt,1, UInt,0, UInt,0, UInt,0x10 )
;SendMessage, 0x80, 0, hIcon ; One affects Title bar and
;SendMessage, 0x80, 1, hIcon ; the other the ALT+TAB menu
Gui, Font, s10
Menu, FileMenu, Add, E&xit, FileClose
Menu, MenuBar, Add, &File, :FileMenu
Menu, OptionsMenu, Add, &Close to Tray, CloseToTray
Menu, OptionsMenu, Add, Open without &Asking, ToggleAsk
Menu, OptionsMenu, Add, Set Output Directory, SetOutput
Menu, MenuBar, Add, &Options, :OptionsMenu
Menu, HelpMenu, Add, &Todo List, Todo
Menu, HelpMenu, Add, &About, About
Menu, HelpMenu, Add
Menu, HelpMenu, Add, &Edit .INI File, EditIni
Menu, MenuBar, Add, &Help, :HelpMenu
Menu, Tray, NoStandard
Menu, Tray, Add, Restore Window, GuiShow
Menu, Tray, Default, Restore Window
Menu, Tray, Click, 1
Menu, Tray, Standard
Gui +DelimiterTab ;Delimiter is `t
Gui, Menu, MenuBar
Gui, Add, Button, x9 y8 w59 h26 gBrowse, &Browse
Gui, Add, ComboBox, x+5 y9 w617 vPathText, %SysDrive%`t`t%PathHistory%
Gui, Add, Text, x9 y42, &Filename:
Gui, Add, ComboBox, x+5 y38 w455 vFileText
Gui, Add, Checkbox, x+5 y42 vSRegEx gSRegEx checked, &RegEx
Gui, Add, Checkbox, x+0 y42 vCase gCase, &Match CaSe
Gui, Add, Text, xp+10 y42 vExtText, Ext:
Gui, Add, Edit, x+5 y38 w55 h22 vFileExt, *
Gui, Add, Button, x9 y66 w75 gClear, &Clear list
Gui, Add, Button, x+5 yp w75 gExport, &Export list
Gui, Add, Button, x506 yp w75 gNewTest DISABLED, NewTest
Gui, Add, Button, x+5 yp w75 gRefine DISABLED, Refine
Gui, Add, Button, x+5 yp w75 gSearchButton +Default, &Search
Gui, Font, s8
Gui, Add, ListView, x10 y98 w680 h269 gClicked vList +AltSubmit, Path `t File `t Size (KB)
Gui, Add, Statusbar, h25
Gui, +Resize +MinSize425x175
Gui, Show, w750 h450
Gui, +LastFound
Gui1 := WinExist()
iniRead, vTrayClose, %iniFile%, Settings, CloseToTray, 1
IfEqual, vTrayClose, 1, Gosub, CloseToTray2
iniRead, vSkipAskOpen, %iniFile%, Settings, SkipAskOpen, 0
IfEqual, vSkipAskOpen, 1, Gosub, ToggleAsk2
iniRead, OutputDir, %iniFile%, Settings, OutputDir, %A_Desktop%
SRegEx:
GuiControlGet, DoRegEx,, SRegEx
If (DoRegEx = 1)
{
GuiControl, Disable, FileExt
GuiControl, Hide, FileExt
GuiControl, Hide, ExtText
GuiControl, Show, Case
GuiControl,, FileText, `t.*`t`t%RegExHistory%
} Else {
GuiControl, Enable, FileExt
GuiControl, Show, FileExt
GuiControl, Show, ExtText
GuiControl, Hide, Case
GuiControl,, FileText, `t*`t`t
}
Case:
GuiControlGet, MatchCase,, Case
vCase := (MatchCase ? "" : "(?i)")
Return
SetOutput:
Gui +OwnDialogs
FileSelectFolder, OutputDir, ::{20d04fe0-3aea-1069-a2d8-08002b30309d} *%OutputDir%, 3
If (OutputDir = "")
iniRead, OutputDir, %iniFile%, Settings, OutputDir, %A_Desktop%
Else
iniWrite, %OutputDir%, %iniFile%, Settings, OutputDir
Return
Browse:
Gui +OwnDialogs
FileSelectFolder, vPath, ::{20d04fe0-3aea-1069-a2d8-08002b30309d} *%vPath%, 0
vPath := (vPath = "" ? SysDrive : vPath)
GuiControl, Text, PathText, %vPath%
Return
Clear:
Searching =
LV_Delete()
SB_SetText("")
GuiControl,, &Stop, &Search
GuiControl, Disable, Refine
Return
Export:
xFiles := LV_GetCount()
Loop, %xFiles%
{
LV_GetText(CurFolder, A_Index, 1)
LV_GetText(CurFile, A_Index, 2)
Output .= CurFolder CurFile "`n"
}
If (Output = "")
MsgBox Nothing to save.
Else
{
OutputFile = Results %A_YYYY%-%A_MM%-%A_DD%_%A_Hour%%A_Min%.txt
FileAppend, %Output%, %OutputDir%\%OutputFile%
MsgBox % (ErrorLevel = 0 ? "List exported to" : "Error writing") " file:`n%OutputDir%\%OutputFile%"
}
Return
Refine:
MsgBox Under Construction
Return
SearchButton:
If Searching
Searching =
Else
{
Searching = 1
SetTimer, Search, -1
}
;GuiControl, Enable, Refine
Return
Search:
GuiControlGet, vPath,, PathText
GuiControlGet, vFile,, FileText
GuiControlGet, vExt,, FileExt
GoSub UpdateHistory
If (vPath = "")
{
vPath = %SysDrive%
GuiControl,, PathText, %vPath%
}
If (vFile = "")
{
Gosub SRegEx
Goto Search
}
If (vExt = "")
vExt = *
LV_Delete()
GuiControl,, &Search, &Stop
;GuiControl, -Redraw, List
SB_SetText(" Searching...")
If !(SubStr(vPath, 0, 1)=="\")
vPath .= "\"
If (DoRegEx = 1)
{
Loop, %vPath%*,0,1
{
If RegExMatch(A_LoopFileName, vCase "^" vFile "$")
Lv_Add("", A_LoopFileDir "\", A_LoopFileName, A_LoopFileSizeKB)
If !Searching
Break
}
} Else {
Loop, %vPath%%vFile%.%vExt%,0,1
{
Lv_Add("", A_LoopFileDir "\", A_LoopFileName, A_LoopFileSizeKB)
If !Searching
Break
}
}
;GuiControl, +Redraw, List
Gosub UpdateSB
Searching =
GuiControl,, &Stop, &Search
Return
; List View
Clicked:
LV_GetText(SelFolder, A_EventInfo, 1)
LV_GetText(SelFile, A_EventInfo, 2)
If A_GuiEvent = Normal
Gosub UpdateSB
If A_GuiEvent = DoubleClick
{
RowNum = %A_EventInfo%
Gui, 2:+owner1
Gui, 2:Add, Text, x10 y10, Path and Original Name:
Gui, 2:Add, Edit, x10 y+5 w415 r1 Disabled, %SelFolder%
Gui, 2:Add, Edit, x10 y+0 w415 r1 vOldName Disabled, %SelFile%
Gui, 2:Add, Text, x10 y+5, New Name:
Gui, 2:Add, Edit, x10 y+5 w415 r1 vNewName, %SelFile%
;Gui, 2:Add, Button, x10 y+20 w75, Close
Gui, 2:Add, Button, x10 y+20 w75, Rename
Gui, 2:Add, Button, x+10 w75, Recycle
Gui, 2:Add, Button, x+10 w75, Properties
Gui, 2:Add, Button, x+10 w75, Open
Gui, 2:Add, Button, x+10 w75, Folder
Gui, 2:Show, w435 h175, File Options
Gui, 1:+Disabled
}
Return
UpdateSB:
/*
nFiles := LV_GetCount("s")
Loop, %nFiles% {
ToolTip % A_Index
}
*/
SB_SetText(" " LV_GetCount() " files found`t" LV_GetCount("s") " file" (LV_GetCount("s") > 1 ? "s" : "" ) " selected`t <FILESIZEHERE> KB ")
Return
NewTest:
Return
; GUI Resize
GuiSize:
;WinGetPos,,, vW, vH, A
GuiGetSize(vW, vH, 1)
Col1 := Floor((vW-100)*0.5)
Col2 := Floor((vW-100)*0.5)
LV_ModifyCol(1,Col1)
LV_ModifyCol(2,Col2)
LV_ModifyCol(3, "59 Integer Desc")
GuiControl, Move, List, % "w" vW-20 "h" vH-131
GuiControl, Move, PathText, % "w" vW-83
GuiControl, Move, FileText, % "w" vW-248
GuiControl, Move, SRegEx, % "x" vW-167
GuiControl, Move, Case, % "x" vW-103
GuiControl, Move, Ext:, % "x" vW-91
GuiControl, Move, FileExt, % "x" vW-65
GuiControl, Move, NewTest, % "x" vW-244
GuiControl, Move, Refine, % "x" vW-164
GuiControl, Move, &Search, % "x" vW-84
GuiControl, Move, &Stop, % "x" vW-84
SetTimer, DoRedraw, -100
Return
DoRedraw:
WinSet, Redraw,, A
Return
; GUI Settings
GuiShow:
Gui, Show
Return
GuiClose:
If (vTrayClose = 1)
{
Gui, Hide
Gosub WriteHistory
} else {
FileClose:
Gosub WriteHistory
ExitApp
}
Return
CloseToTray:
iniWrite, %vTrayClose%, %iniFile%, Settings, CloseToTray
CloseToTray2:
Menu, OptionsMenu, ToggleCheck, &Close to Tray
vTrayClose := IsMenuItemChecked( 1, 0, Gui1 )
Return
ToggleAsk: ;writes the value on startup... I want to avoid this
iniWrite, %vSkipAskOpen%, %iniFile%, Settings, SkipAskOpen
ToggleAsk2:
Menu, OptionsMenu, ToggleCheck, Open without &Asking
vSkipAskOpen := IsMenuItemChecked( 1, 1, Gui1 )
Return
Todo:
Gui +OwnDialogs
MsgBox,, Todo List, %ToDoList%
Return
About:
Gui +OwnDialogs
MsgBox,, About Find Files RegEx.ahk, Blah Blah Blah.
Return
EditIni:
Run %iniFile%
Return
; History
ReadHistory: ;Rework into a function?
For index, value in PathArray {
iniRead, PathHistory%index%, %iniFile%, PathHistory, %index%, %A_Space%
PathArray[Index] := PathHistory%Index%
PathHistory .= PathArray[Index] "`t"
}
PathHistory := RegExReplace(PathHistory, "\t*$")
For index, value in RegExArray {
iniRead, RegExHistory%index%, %iniFile%, RegExHistory, %index%, %A_Space%
RegExArray[index] := RegExHistory%index%
RegExHistory .= RegExArray[index] "`t"
}
RegExHistory := RegExReplace(RegExHistory, "\t*$")
Return
UpdateHistory: ;Rework into a function?
If !(vPath = SysDrive) ;Skip adding system root
Assign(PathArray, vPath)
PathHistory := "`t"
For index, value in PathArray {
PathHistory .= value "`t"
}
PathHistory := RegExReplace(PathHistory, "\t*$")
GuiControl,, PathText, `t%SysDrive%%PathHistory%
GuiControl, ChooseString, PathText, %vPath%
If !(vFile = ".*") ;Skip adding ".*"
Assign(RegExArray, vFile)
RegExHistory := "`t"
For index, value in RegExArray {
RegExHistory .= value "`t"
}
RegExHistory := RegExReplace(RegExHistory, "\t*$")
GuiControl,, FileText, `t.*%RegExHistory%
GuiControl, ChooseString, FileText, %vFile%
Return
WriteHistory: ;Rework into a function?
For index, value in PathArray
iniWrite, %value%, %iniFile%, PathHistory, %index%
For index, value in RegExArray
iniWrite, %value%, %iniFile%, RegExHistory, %index%
Return
; Popup Menu
2ButtonRename:
GuiControlGet, NewName,, NewName
Gui, +OwnDialogs
MsgBox, 4, Rename?, %SelFolder%`n%SelFile%`n%NewName%
IfMsgBox, Yes
{
FileMove, %SelFolder%%SelFile%, %SelFolder%%NewName%
Gui, 1:Default
LV_Modify(RowNum,"Col2",NewName)
}
Return
2ButtonRecycle:
Gui, +OwnDialogs
MsgBox, 4, Recycle?, Are you sure you wish to send this file to the Recycle Bin?`n%SelFolder%%SelFile%
IfMsgBox, Yes
{
FileRecycle, %SelFolder%%SelFile%
If !(ErrorLevel = 0)
MsgBox, An error occured. Could not recycle the file:`n%SelFolder%%SelFile%
Else {
Gui, 1:Default
LV_Delete(RowNum)
}
}
Goto 2GuiClose
2ButtonOpen:
Gui, +OWnDialogs
If !(vSkipAskOpen = 1) {
MsgBox, 4, Open?, Are you sure you wish to run this file?`t %SelFolder%%SelFile%
IfMsgBox, Yes
DoOpen = 1
}
If (vSkipAskOpen = 1) OR (DoOpen = 1)
Run, %SelFolder%%SelFile%
DoOpen = 0
Goto 2GuiClose
2ButtonProperties:
Run, properties %SelFolder%%SelFile%
Return
2ButtonFolder:
Run, explore %SelFolder%
Goto 2GuiClose
2GuiClose:
2GuiEscape:
2ButtonClose:
Gui, 1:-Disabled
Gui, 2:Destroy
Return
; Functions
IsMenuItemChecked( MenuPos, SubMenuPos, hWnd ) { ; By Obi / Lexikos
;Original version: www.autohotkey.com/forum/viewtopic.php?p=203606#203606
hMenu :=DllCall("GetMenu", UInt,hWnd )
hSubMenu := DllCall("GetSubMenu", UInt,hMenu, Int,MenuPos )
VarSetCapacity(mii, 48, 0), NumPut(48, mii, 0), NumPut(1, mii, 4)
DllCall( "GetMenuItemInfo", UInt,hSubMenu, UInt,SubMenuPos, Int, 1, UInt,&mii )
Return ( NumGet(mii, 12) & 0x8 ) ? 1 : 0
}
GuiGetSize( ByRef W, ByRef H, GuiID=1 ) {
Gui %GuiID%:+LastFound
VarSetCapacity( rect, 16, 0 )
DllCall("GetClientRect", uint, MyGuiHWND := WinExist(), uint, &rect )
W := NumGet( rect, 8, "int" )
H := NumGet( rect, 12, "int" )
}
Assign(ByRef varName, newVal){ ;thanks Elesar
for index, value in varName
{
if (value == newVal)
varName.Remove(index)
}
varName.Insert(1, newVal)
varName.Remove(11)
}