-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathLightningRenamer.ahk
2365 lines (2230 loc) · 77.6 KB
/
LightningRenamer.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
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;=================================================
;== Lightning Renamer by no1readsthese ==
;== Version 1.5 ==
;=================================================
;=================================================
;==Features=======================================
;== - Options: ==
;== Spacing ==
;== Case Correction ==
;== String Replacement ==
;== Insert String ==
;== Insert Counter ==
;== Bracket Deletion ==
;== Character Deletion ==
;== Amber's Counter ==
;== Rename From List ==
;== Regular Expression ==
;== Custom Rename ==
;== - Use Batches To Set Up Multiple Renaming ==
;== Options ==
;== - Undo Button To Undo Stuff ==
;== - You Can Use The Command Line Or ==
;== Drag `n Drop Files And Folders On To ==
;== The Script File (Not Gui) To Rename ==
;== Using The Default Batch Without Opening ==
;== The GUI ==
;=================================================
;==Wish List======================================
;== - MP3 Tag Info Option To Work ==
;== - An Option To Apply The Changes To ==
;== The Extention ==
;== - Optimize Algorithms For Speed ==
;== - Any Suggestions Are Appreciated ==
;=================================================
;=================================================
/*
Change Log:
v1.0
- Inital Release
v1.1
- Multiple Batches
- Real Time Preview For Custom Option
- Changed Delete/DeleteAll To Clear/ClearAll
- Added "Clear Dead" Button
v1.2
- Added Amber's Counter Option
v1.3
- Files Renamed To An Existing File's Name Will Be Renamed With '_1' Or Something Similar At The End
- Real Time Preview For Regular Expression Option
- Added Rename From List Option
- Fixed Some Minor Bugs
v1.4
- Added Undo Button
- Fixed '0 Read As Blank' Bug
v1.5
- Fixed Renaming Conflict Bug
*/
/*
Thanks To:
- Keybored For Suggestions
- Razlin For Reporting Bugs
- TBetti For Suggestions and Reporting Bugs
*/
;=================================================
;================Auto-Execute=====================
;=================================================
#NoTrayIcon
#NoEnv
#SingleInstance OFF
SetWorkingDir, %A_ScriptDir%
If 0>0
{
GoSub, ProcessCommandLine
ExitApp
}
ScriptName:="Lightning Renamer 1.5"
Gosub, ReadINIFile
Gosub, BuildGUI
Return
;=================================================
;==================Build Gui======================
;=================================================
BuildGUI:
FileLabel := " Files "
ActionLabel := " Actions "
BatchLabel := " Batch Rename "
Blank := " "
B := " "
TemplateHelp=
(
Notes:
- `%name`% = Original File Name (Without Extention)
- `%ext`% = Original Extention (With the Dot)
- `%list`% = Items Off of the List Described in the Rename Using A List Section
- `%num`% = Counter Described in the Insertion Section ( Starting at
)
RegExNotes=
(
Notes:
- 'Regular Expression' Field Should Contain a Perl-Compatible Regular Expression (PCRE) Pattern
That Includes the Extention
- 'New Name' Field Should Contain the File's New Name Implimenting Backreferences
ie: $1 - $9 and ${10} +
- Can Be Used as RegExReplace By Placing the Replacement String in the New Name Field
- For More, See
)
AmberText=
(
- Click The Button To Open The Renaming Window
- Drag N' Drop Files On Renaming Window To Rename Using The Counter Below
- The Renamed File Will Be Taken Off The File List
- Counter Resets When Renaming Window Is Closed
`nCounter:
)
ListNotes=
(
Notes:
- Each Line From This List Will Be Used As A Name For A File. Items Are Used Sequentially
- If Lines Are Empty Or If There Are Not Enough Line, The Corresponding Files Will Not Be Renamed
)
PreviousAction =
AList:="start,Spacing,Case Correction,String Replacement,Insertion,Bracket Deletion,Character Deletion,Amber's Counter,Rename From List,Regular Expression,Custom,"
StringSplit, ArrayList, AList, `,
cnt:=ArrayList%0%
StringReplace, ListOfBatchNames, ListOfBatchNames, ||, |, All
StringReplace, ListOfBatchNames, ListOfBatchNames, |, ||
; Menus
Menu, FileContextMenu, Add, Clear Selected, ClearFileListRows
Menu, FileContextMenu, Add, Clear Dead, ClearDeadFileListRows
Menu, FileContextMenu, Add, Clear All, ClearAllFileListRows
Menu, FileContextMenu, Add
Menu, FileContextMenu, Add, Properties, ContextProperties
Menu, StringReplaceContextMenu, Add, Edit, EditSRL
Menu, StringReplaceContextMenu, Add
Menu, StringReplaceContextMenu, Add, Move Up, MoveUpSRL
Menu, StringReplaceContextMenu, Add, Move Down, MoveDownSRL
Menu, StringReplaceContextMenu, Add
Menu, StringReplaceContextMenu, Add, Remove, RemoveSRL
Menu, StringReplaceContextMenu, Add, Remove All, ClearSRL
Menu, BatchContextMenu, Add, Move Up, MoveUpBL
Menu, BatchContextMenu, Add, Move Down, MoveDownBL
Menu, BatchContextMenu, Add
Menu, BatchContextMenu, Add, Remove, RemoveBL
Menu, BatchContextMenu, Add, Remove All, RemoveAllBL
Menu, BatchNameContextMenu, Add, Load, LoadBatch
Menu, BatchNameContextMenu, Add, Rename, RenameBatchName
Menu, BatchNameContextMenu, Add
Menu, BatchNameContextMenu, Add, Delete, DeleteBatch
Menu, UndoContextMenu, Add, Undo Last, UndoLastRename
Menu, UndoContextMenu, Add, Undo Session, UndoSession
Menu, FileContextMenu, Default, Properties
Menu, StringReplaceContextMenu, Default, Edit
Menu, BatchContextMenu, Default, Remove
Menu, BatchNameContextMenu, Default, Load
; Outside of Tabs
Gui, Add, GroupBox, x5 y365 w690 h80, Preview
Gui, Add, Text, xp+15 yp+25, Current File Name:`n`nNew File Name:
Gui, Add, Text, x130 y390 w425 h50 vPreviewBatchShow
Gui, Add, Button, x+5 yp+10 w40 h35 Disabled vUndoButton gUndoLastRename, Undo
Gui, Add, Tab2, x5 y5 w690 h350 vTabs, %FileLabel%||%ActionLabel%|%BatchLabel%
; Inside File Tab
Gui, Tab, 1
Gui, Add, Button, x15 y40 w90 h20 gGUIFiles, Add Files
Gui, Add, Button, x115 y40 w90 h20 gGUIFolder, Add Folder
Gui, Add, Checkbox, x230 y40 h20 vSubFolder Checked%SubFolder%, Include Sub-Folders
Gui, Add, Button, x395 y40 w90 h20 gClearFileListRows, Clear Sel.
Gui, Add, Button, xp+100 y40 w90 h20 gClearDeadFileListRows, Clear Dead
Gui, Add, Button, x595 y40 w90 h20 gClearAllFileListRows, Clear All
Gui, Add, ListView, x15 y70 w670 h270 vFileList NoSortHdr, File Name|Folder|Type
LV_ModifyCol(1, 100)
LV_ModifyCol(2, 200)
LV_ModifyCol(3, 40)
Gui, Add, Button, x605 y385 w80 h50 gRenameBatchButton, Rename`nFiles
; Inside Action Tab
Gui, Tab, 2
Gui, Add, ListBox, x15 y40 w150 h270 vActionList gActionList, Spacing||Case Correction|String Replacement|Insertion|Bracket Deletion|Character Deletion|Amber's Counter|Rename From List|Regular Expression|Custom
Gui, Add, Button, x45 y310 w90 h30 vAddToBatch gAddGUI, Add To Batch
Gui, Add, Text, x130 y390 w425 h50 vPreviewShow
Gui, Add, Button, x605 y385 w80 h50 vRenameButton gRenameButton, Rename`nFiles
; Spacing Options
Gui, Add, GroupBox, x175 y40 w510 h130 vSpaceGroup
Gui, Add, Checkbox, x185 y60 h30 vDelExtraSpace gPreview Checked%DelExtraSpace%, Remove Extra Spacing
Gui, Add, Checkbox, x185 yp+30 h30 vDotToSpace gPreview Checked%DotToSpace%, . (dot) => Space
Gui, Add, Checkbox, x295 yp h30 vCommaToSpace gPreview Checked%CommaToSpace%, , (comma) => Space
Gui, Add, Checkbox, x425 yp h30 vUnderToSpace gPreview Checked%UnderToSpace%, _ => Space
Gui, Add, Checkbox, x185 yp+30 h30 vSkipNumSeq gPreview Checked%SkipNumSeq%, Skip Number Sequences (ex. 1.2.3)
; Case Correction
Gui, Add, Radio, x185 y60 h30 vCapFirst gPreview Checked%CapFirst%, Capitalize first word
Gui, Add, Radio, xp yp+30 h30 vCapAll gPreview Checked%CapAll%, Capitalize Every Word
Gui, Add, Radio, xp yp+30 h30 vUppercase gPreview Checked%Uppercase%, ALL UPPER CASE
Gui, Add, Radio, xp yp+30 h30 vLowercase gPreview Checked%Lowercase%, all Lower case
Gui, Add, Radio, xp yp+30 h30 vInvertCase gPreview Checked%InvertCase%, iNVERT cASE
; Brackets Options
Gui, Add, Text, x185 y60 vBracketText1, Bracket Type:
Gui, Add, Radio, x205 y80 vSquareBracket gPreview Checked%SquareBracket%, [ ... ]
Gui, Add, Radio, x255 y80 vCurlyBracket gPreview Checked%CurlyBracket%, { ... }
Gui, Add, Radio, x305 y80 vRoundBracket gPreview Checked%RoundBracket%, ( ... )
Gui, Add, Checkbox, x185 y120 vOpenBracket gPreview Checked%OpenBracket%, Include Open Brackets: ' ... ] ' or ' [ ... '
Gui, Add, Text, x185 yp+40 vBracketText2, Start from:
Gui, Add, Radio, x205 yp+20 vStartLeft gPreview Checked%StartLeft%, Left Side
Gui, Add, Radio, x290 yp vStartRight gPreview Checked%StartRight%, Right Side
Gui, Add, Text, x185 yp+40 vBracketText3, Number of Bracket Blocks to Delete:
Gui, Add, Radio, x205 yp+20 vDelAllBracket gPreview Checked%DelAllBracket%, Delete All
Gui, Add, Radio, x330 yp vDelNumBracket gPreview Checked%DelNumBracket%, Delete Only
Gui, Add, Edit, x350 yp+20 w40 vNumBracket gPreview Limit2
Gui, Add, UpDown, vNumBracket2 Range1-99, %NumBracket%
Gui, Add, Text, x340 yp+30 vBracketText4, Bracket Block
; String Replacement Options
Gui, Add, Text, x175 y40 vStringReplaceText, Search For:%Blank% %B% %B%Replaced By:
Gui, Add, Edit, x190 y60 w150 vSearchField
Gui, Add, Edit, x380 y60 w150 vReplaceField
Gui, Add, Button, x580 y50 w90 h25 vAddStringReplace gAddStringReplace, Add
Gui, Add, ListView, x180 y110 w380 h230 vStringReplaceList Grid NoSortHdr -Multi, Search For|Replace By
LV_ModifyCol(1, 187)
LV_ModifyCol(2, 187)
Gui, Add, Checkbox, x580 y110 vReplaceAll gPreview Checked%ReplaceAll%, Replace `nAll Occurrences
Gui, Add, Checkbox, x580 y150 vReplaceWithCase gPreview Checked%ReplaceWithCase%, Case Sensitive
Gui, Add, Button, x608 y170 w30 h30 vMoveUpSRL gMoveUpSRL, /\
Gui, Add, Button, x608 y205 w30 h30 vMoveDownSRL gMoveDownSRL, \/
Gui, Add, Button, x578 y310 w90 h30 vClearSRL gClearSRL, Remove All
Gui, Add, Button, x578 yp-35 w90 h30 vRemoveSRL gRemoveSRL, Remove
Gui, Add, Button, x578 yp-35 w90 h30 vEditSRL gEditSRL, Edit
; Insertion Options
Gui, Add, GroupBox, x175 y40 w510 h80 vInsertStringGroup, %Blank%
Gui, Add, GroupBox, x175 y130 w510 h80 vInsertCounterGroup, %Blank%
Gui, Add, Radio, x185 y36 vInsertStringRadio gPreview Checked%InsertStringRadio%, Insert String:
Gui, Add, Radio, x185 y126 vInsertCounterRadio gPreview Checked%InsertCounterRadio%, Insert Counter:
Gui, Add, Text, x185 y60 vInsertStringText, String to Insert:
Gui, Add, Edit, x205 y80 w400 vInsertString gPreview, %InsertString%
Gui, Add, Text, x185 y150 vInsertCounterText, Start At:%B%%B%Number of Digits:%B% Increment by:
Gui, Add, Edit, x200 y170 w50 vCounterStart gPreview
Gui, Add, UpDown, vCounterStart2, %CounterStart%
Gui, Add, Edit, x320 y170 w50 vCounterDigits gPreview
Gui, Add, UpDown, vCounterDigits2 Range1-10, %CounterDigits%
Gui, Add, Edit, x450 y170 w50 vCounterIncrement gPreview
Gui, Add, UpDown, vCounterIncrement2 Range1-1000000, %CounterIncrement%
Gui, Add, Checkbox, xp+90 y150 vAddSpaceBefore gPreview Checked%AddSpaceBefore%, Add a Space Before
Gui, Add, Checkbox, xp yp+30 vAddSpaceAfter gPreview Checked%AddSpaceAfter%, Add a Space After
Gui, Add, Text, x185 y240 vInsertAtPositionText, At Position:
Gui, Add, Edit, x200 y260 w50 vInsertAtPosition gPreview
Gui, Add, UpDown, vInsertAtPosition2, %InsertAtPosition%
Gui, Add, Radio, x280 y260 vInsertFromBeginning gPreview Checked%InsertFromBeginning%, From Beginning
Gui, Add, Radio, x400 y260 vInsertFromEnd gPreview Checked%InsertFromEnd%, From End
; Char Deletion Options
Gui, Add, Text, x185 y60 vCharDel, Number of Characters to Delete:
Gui, Add, Edit, xp+25 yp+20 w50 vCharDelCount gPreview
Gui, Add, UpDown, vCharDelCount2 Range1-100, %CharDelCount%
Gui, Add, Radio, x185 y170 vDelAfter gPreview Checked%DelAfter%, After the String:
Gui, Add, Radio, x320 yp vDelBefore gPreview Checked%DelBefore%, Before the String:
Gui, Add, Radio, x185 y115 vDelFromPositionText gPreview Checked%DelFromPositionText%, From Position:
Gui, Add, Edit, xp+25 yp+20 w50 vDelFromPosition gPreview
Gui, Add, UpDown, vDelFromPosition2, %DelFromPosition%
Gui, Add, Radio, x280 yp+3 vDelFromBeginning gPreview Checked%DelFromBeginning%, From Beginning
Gui, Add, Radio, xp+130 yp vDelFromEnd gPreview Checked%DelFromEnd%, From End
Gui, Add, Edit, x210 y190 w400 vDelFromString gPreview, %DelFromString%
; Regular Expression Options
Gui, Add, Text, x185 y60 VRegExText1, Regular Expression:
Gui, Add, Edit, xp+25 yp+30 w370 vRegEx gPreview, %RegEx%
Gui, Add, Text, xp-25 yp+40 vRegExText2, New Name:
Gui, Add, Edit, xp+25 yp+30 w370 vRegExNewName gPreview, %RegExNewName%
Gui, Add, Text, xp-25 yp+50 vRegExHelp1, %RegExNotes%
Gui, Font, underline
Gui, Add, Text, xp+89 yp+78 vRegExHelp2 gRegExHelp cBlue, Help
Gui, Font, Norm
; Custom Options
Gui, Add, Text, x185 y60 vTemplateText, Template:
Gui, Add, Edit, xp+25 yp+30 w400 vTemplate gPreview, %Template%
Gui, Add, Text, x185 y140 w500 h200 vTemplateNotes, %TemplateHelp%
; Amber's Counter
Gui, Add, Text, x185 y55 vAmberCounterText, %AmberText%
Gui, Add, Button, x535 y385 w150 h50 vAmberButton gAmberGUI, Open Renaming Window
;Rename From List Option
Gui, Add, Button, x175 y45 w90 h20 vListClear gListOptionButtons, Clear
Gui, Add, Button, x+10 yp w90 h20 vListOpen gListOptionButtons, Open...
Gui, Add, Button, x+10 yp w90 h20 vListSave gListOptionButtons, Save...
Gui, Add, Edit, x175 y+10 w510 h175 -Wrap vListOfNames gPreview
Gui, Add, Checkbox, xp y+10 vListOriginalExt Checked%ListOriginalExt% gPreview, Keep Original Extention
Gui, Add, Checkbox, xp y+10 vListExt Checked%ListExt% gPreview, Use Items As Extentions
Gui, Add, Text, xp y+10 vListText, %ListNotes%
; Inside Batch Tab
Gui, Tab, 3
Gui, Add, ListView, x15 y40 w630 r7 vBatchList NoSortHdr -Multi, Default
Gui, Add, Button, xp+640 yp+40 w30 h30 gMoveUpBL, /\
Gui, Add, Button, xp yp+40 w30 h30 gMoveDownBL, \/
Gui, Add, Button, x450 yp+85 w90 h30 gRemoveBL, Remove
Gui, Add, Button, xp+100 yp w90 h30 gRemoveAllBL, Remove All
Gui, Add, Text, x370 yp+50, Notes:`n - There Can Be Only 1 Counter Per Batch
Gui, Add, GroupBox, x15 y195 w335 h150, Stored Batches
Gui, Add, ListBox, xp+10 yp+20 w250 h125 vBatchNameList, %ListOfBatchNames%
Gui, Add, Button, xp+258 yp+5 w60 h20 gLoadBatch, Load
Gui, Add, Button, xp yp+35 w60 h20 vRenameBatchNameButton gRenameBatchName, Rename
Gui, Add, Button, xp yp+50 w60 h20 vDelBatchButton gDeleteBatch, Delete
Gui, Add, Button, x605 y385 w80 h50 gRenameBatchButton, Rename`nFiles
Gui, Tab
Gosub, LoadSRL
GoSub, LoadBatch
Gosub, ActionList
cnt:=1
Gui, ListView, FileList
Gui, Show, Center w700 h450, %ScriptName%
Return
GuiContextMenu:
If A_GuiControl=FileList
Menu, FileContextMenu, Show, %A_GuiX%, %A_GuiY%
Else If A_GuiControl=StringReplaceList
Menu, StringReplaceContextMenu, Show, %A_GuiX%, %A_GuiY%
Else If A_GuiControl=BatchList
Menu, BatchContextMenu, Show, %A_GuiX%, %A_GuiY%
Else If A_GuiControl=BatchNameList
Menu, BatchNameContextMenu, Show, %A_GuiX%, %A_GuiY%
/*
Else If A_GuiControl=UndoButton
{
GuiControlGet, Temp, Enabled, UndoButton
Menu, UndoContextMenu, % (Temp ? "Enable" : "Disable") , Undo Last
Menu, UndoContextMenu, Show, %A_GuiX%, %A_GuiY%
}
*/
Return
GuiDropFiles:
Gui, ListView, FileList
GuiControl, -Redraw, FileList
Gui, Submit, NoHide
FileList = %A_GuiEvent%
Loop, Parse, FileList, `n
{
FileGetAttrib, test, %A_LoopField%
IfInString, test, D
Loop, %A_LoopField%\*,0,%SubFolder%
LV_Add("", A_LoopFileName, A_LoopFileDir, A_LoopFileExt)
Else
{
SplitPath, A_LoopField, FileName, FilePath, FileExt
LV_Add("", FileName, FilePath, FileExt)
}
}
GuiControl, +Redraw, FileList
LV_ModifyCol(1, "AutoHdr")
LV_ModifyCol(2, "AutoHdr")
GuiControl,, Tabs, |%FileLabel%||%ActionLabel%|%BatchLabel%
Gosub, PreviewAll
Return
RegExHelp:
HelpDialog=
(
Examples:
`n**Swapping Artist and Title From MP3 File Names:
`n - Regular Expression -
( .* ) - ( .* )\.mp3
`n - New Name -
$2 - $1.mp3
`n`n`n**Extract Episode Number and Title From Series Video Files With
Episode Number as SnnEmm Followed by Title:
`n - Regular Expression -
Robot\.Chicken\.S( [ 0-9 ] { 2 } )E( [ 0-9 ] { 2 } )\.( .* )\.XViD\.avi `n
- New Name -
Robot Chicken - $1$2 - $3.avi
`n`n`nStill Don't Get It?
Google ' Perl-Compatible Regular Expression (PCRE) ' or ' RegEx '`n`n
)
Gui, 2: +Owner1 +ToolWindow
Gui, +Disabled
Gui, 2:Add, Text, x20 y20, %HelpDialog%
Gui, 2:Show,, Help
Return
AddGUI:
Gui, Submit, NoHide
StringReplace, ListOfBatchNames, ListOfBatchNames, ||, |, All
StringReplace, ListOfBatchNames, ListOfBatchNames, |, |, UseErrorLevel
Temp:=ErrorLevel
StringReplace, ListOfBatchNames, ListOfBatchNames, %BatchNameList%|, %BatchNameList%||
Gui, 3: +Owner1 +ToolWindow -SysMenu
Gui, +Disabled
Gui, 3:Add, Text,, Add To:
Gui, 3:Add, ListBox, xp+20 yp+45 w150 r%Temp% vExistBatchName, %ListOfBatchNames%
Gui, 3:Add, Edit, xp y+35 w150 vNewBatchName, New Batch
Gui, 3:Add, GroupBox,xp-20 yp+30 w170
Gui, 3:Add, Button, xp+90 yp+15 w70 h30 g3GuiClose, Cancel
Gui, 3:Add, Button, xp-80 yp w70 h30 gAddToBatch, OK
Gui, 3:Add, Radio, xp-10 yp-70 vAddToNew, New Batch
Gui, 3:Add, Radio, xp ym+20 vAddToExist Checked, Existing Batch
Gui, 3:Show,, %A_Space%
Return
3GuiClose:
2GuiClose:
Gui, 1:-Disabled
Gui, Destroy
Return
AmberGUI:
Gui, Submit
Counter:=CounterStart-1
IncrementCounter(Counter, CounterDigits, CounterIncrement, AddSpaceBefore, AddSpaceAfter)
Gui, 4:+ToolWindow +AlwaysOnTop
Gui, 4:Add, Text, xp y90 w240 Center vAmberGUIText, % "Next File Number:" . ((!AddSpaceBefore) ? " " : "") . Counter
Gui, 4:Show, w250 h200
Return
4GuiDropFiles:
Gui, 1:Default
Gui, ListView, FileList
Loop, Parse, A_GuiEvent, `n
{
FileGetAttrib, test, %A_LoopField%
IfInString, test, D
Continue
SplitPath, A_LoopField, FullFileName, FilePath, FileExt, FileName
Loop % LV_GetCount()
{
LV_GetText(Temp1, A_Index, 1)
IfNotEqual, FullFileName, %Temp1%
Continue
LV_GetText(Temp2, A_Index, 2)
IfNotEqual, FilePath, %Temp2%
Continue
LV_Delete(A_Index)
Break
}
FileName:=InsertString(FileName, Counter, InsertAtPosition, InsertFromBeginning)
FileMove, %A_LoopField%, %FilePath%\%FileName%.%FileExt%
IncrementCounter(Counter, CounterDigits, CounterIncrement, AddSpaceBefore, AddSpaceAfter)
}
Gui, 4:Default
GuiControl,, AmberGUIText, % "Next File Number:" . ((AddSpaceBefore) ? "" : " ") . Counter
Return
4GuiClose:
Gui, Destroy
Gui, 1:Default
Gui, Show
Return
;=================================================
;====================Previews=====================
;=================================================
PreviewAll:
Gosub, PreviewBatch
Gosub, Preview
Return
Preview:
Gui, Submit, NoHide
LV_GetText(FullFileName, 1, 1)
LV_GetText(FullFilePath, 1, 2)
If Not FullFileName
{
GuiControl, Text, PreviewShow,
Return
}
If PreviewBatch
{
Gosub, BatchCounter
Gosub, BatchRename
}
Else
{
Counter:=CounterStart-1
Gosub, RenameFile
}
List:=ListOfNames
PreviewNew:=NewName
PreviewOld:=FullFileName
If PreviewBatch
GuiControl, Text, PreviewBatchShow, %PreviewOld%`n`n%PreviewNew%
Else
GuiControl, Text, PreviewShow, %PreviewOld%`n`n%PreviewNew%
Return
PreviewBatch:
PreviewBatch:=1
Gosub, Preview
PreviewBatch:=0
Return
;=================================================
;==================Rename Action==================
;=================================================
RenameButton:
Gui, +OwnDialogs
Gui, Submit, NoHide
Gui, ListView, FileList
GoSub, ClearDeadFileListRows
ListLength:=LV_GetCount()
If Not ListLength
{
MsgBox, No Files. Please Add Atleast 1 File To Rename
Return
}
If Not BatchButton
Counter:=CounterStart-1
List:=ListOfNames
NumOfFilesRenamed:=0
BackupRename:=0
GuiControl, -Redraw, FileList
Loop %ListLength%
{
LV_GetText(FullFileName, A_Index, 1)
LV_GetText(FullFilePath, A_Index, 2)
If BatchButton
Gosub, BatchRename
Else
Gosub, RenameFile
OldFilePath:=FullFilePath "\" FullFileName
NewFilePath:=FullFilePath "\" NewName
If !(OldFilePath == NewFilePath)
{
If (OldFilePath != NewFilePath) && FileExist(NewFilePath)
{
SplitPath, NewName,,, FileExt, FileName
Loop
{
NewFilePath := FullFilePath "\" FileName "_" A_Index "." FileExt
IfNotExist, %NewFilePath%
Break
}
}
FileMove, %OldFilePath%, %NewFilePath%
LV_Modify(A_Index, "", NewName, FullFilePath)
NumOfFilesRenamed++
}
BackupRename := (BackupRename) ? (BackupRename "`n" NewFilePath ">" OldFilePath) : (NewFilePath ">" OldFilePath)
}
LV_ModifyCol(1, "AutoHdr")
LV_ModifyCol(2, "AutoHdr")
LV_ModifyCol(3, 40)
GuiControl, +Redraw, FileList
BackupSession:=BackupRename BackupSession
If NumOfFilesRenamed
GuiControl, Enable, UndoButton
Gosub, PreviewAll
MsgBox,, %A_Space%, Done!`n%NumOfFilesRenamed% Files Renamed!
Return
RenameBatchButton:
Gui, ListView, BatchList
ListLength:=LV_GetCount()
If Not ListLength
{
Gui, +OwnDialogs
MsgBox, Nothing To Do. Please Add Atleast 1 Action To Batch
Return
}
Gosub, BatchCounter
Gui, ListView, FileList
BatchButton:=1
Gosub, RenameButton
BatchButton:=0
Return
UndoLastRename:
Undo( "Last", BackupRename)
Return
UndoSession:
Undo( "Session", BackupSession)
Return
Undo( Type, Backup)
{
Gui, ListView, FileList
GuiControl, -Redraw, FileList
LV_Delete()
If Type = Last
{
Loop, Parse, Backup, `n
{
StringSplit, FileNames, A_LoopField, >
SplitPath, FileNames2, FullFileName, FilePath, FileExt, FileName
If !(FileNames1==FileNames2)
{
If (FileNames1!=FileNames2) && FileExist(FileNames2)
Loop
{
FileNames2 := FilePath "\" FileName "_" A_Index "." FileExt
IfNotExist, %FileNames2%
Break
}
FileMove, %FileNames1%, %FileNames2%
}
LV_Add( "", FullFileName, FilePath, FileExt)
}
Message:= "Files Restored!"
}
Else If Type = Session
{
;stuff
Message:= "Session Reset`nAll Files Restored"
}
LV_ModifyCol(1, "AutoHdr")
LV_ModifyCol(2, "AutoHdr")
LV_ModifyCol(3, 40)
GuiControl, +Redraw, FileList
GuiControl, Disable, UndoButton
Gosub, PreviewAll
Gui, +OwnDialogs
MsgBox,, %A_Space%, Done!`n%Message%
}
RenameFile:
SplitPath, FullFileName,,, FileExt, FileName
NewName:=FileName
If ActionList=Spacing
{
NewName:=SpaceCorrection(FileName, DelExtraSpace, DotToSpace, CommaToSpace, UnderToSpace, SkipNumSeq)
}
Else If ActionList=Case Correction
{
NewName:=CaseCorrection(FileName, CapFirst, CapAll, Uppercase, Lowercase, InvertCase)
}
Else If ActionList=Bracket Deletion
{
NewName:=DeleteBrackets(FileName, SquareBracket, CurlyBracket, RoundBracket, OpenBracket, StartLeft, DelAllBracket, NumBracket)
}
Else If ActionList=String Replacement
{
Gosub, StringReplacement
}
Else If ActionList=Insertion
{
If InsertStringRadio
NewName:=InsertString(FileName, InsertString, InsertAtPosition, InsertFromBeginning)
Else If InsertCounterRadio
NewName:=InsertCounter(FileName, Counter, CounterDigits, CounterIncrement, AddSpaceBefore, AddSpaceAfter, InsertAtPosition, InsertFromBeginning, InsertFromEnd)
}
Else If ActionList=Character Deletion
{
NewName:=DeleteCharacter(FileName, CharDelCount, DelFromPositionText, DelBefore, DelFromPosition, DelFromBeginning, DelFromString)
}
Else If ActionList=Amber's Counter
{
NewName:=InsertCounter(FileName, Counter, CounterDigits, CounterIncrement, AddSpaceBefore, AddSpaceAfter, InsertAtPosition, InsertFromBeginning, InsertFromEnd)
}
Else If ActionList=Rename From List
{
NewName:=ListRenaming(FileName, FileExt, List, ListOriginalExt, ListExt)
Return
}
Else If ActionList=Regular Expression
{
FileName:=RegExReplace(FullFileName, RegEx, RegExNewName)
NewName:=DeleteIllegalChars(FileName)
Return
}
Else If ActionList=Custom
{
IncrementCounter(Counter, CounterDigits, CounterIncrement)
ListItem:=NextItemInList(List)
NewName:=CustomTemplate(FileName, FileExt, FullFilePath, Template, Counter, ListItem)
Return
}
NewName:=NewName "." FileExt
Return
BatchCounter:
Gui, ListView, BatchList
Loop % LV_GetCount()
{
LV_GetText(Temp1, A_Index, 1)
IfInString, Temp1, Insert Counter
{
Temp3:=RegExMatch(Temp1, "([0-9]{1,2})", TempStart)
Counter:=TempStart-1
Break
}
}
Gui, ListView, FileList
Return
BatchRename:
SplitPath, FullFileName,,, FileExt, FileName
Gui, ListView, BatchList
Loop % LV_GetCount()
{
LV_GetText(BatchString, A_Index, 1)
FileName:=ProccessBatchString(BatchString, FileName, Counter)
}
NewName:=FileName "." FileExt
Gui, ListView, FileList
Return
ProccessBatchString(BatchString, FileName, ByRef Counter)
{
Loop 7
TempArray%A_Index% := ""
Loop, Parse, BatchString, :, %A_Space%
{
If A_Index=1
{
BatchType:=A_LoopField
Continue
}
BatchDetail:=A_LoopField
If BatchType=Spacing
{
IfInString, BatchDetail, Delete Extra Spacing
TempArray1:=1
IfInString, BatchDetail, Dot To Space
TempArray2:=1
IfInString, BatchDetail, Comma To Space
TempArray3:=1
IfInString, BatchDetail, UnderScore To Space
TempArray4:=1
IfInString, BatchDetail, Skip Number Sequences
TempArray5:=1
FileName:=SpaceCorrection(FileName, TempArray1, TempArray2, TempArray3, TempArray4, TempArray5)
}
Else If BatchType=Case Correction
{
If BatchDetail=Capitalize First word
TempArray1:=1
Else If BatchDetail=Capitalize Every Word
TempArray2:=1
Else If BatchDetail=ALL Upper CASE
TempArray3:=1
Else If BatchDetail=all Lower case
TempArray4:=1
Else If BatchDetail=iNVERT cASE
TempArray5:=1
FileName:=CaseCorrection(FileName, TempArray1, TempArray2, TempArray3, TempArray4, TempArray5)
}
Else If BatchType=Bracket Deletion
{
IfInString, BatchDetail, [ ... ]
TempArray1:=1
Else IfInString, BatchDetail, { ... }
TempArray2:=1
Else
TempArray3:=1
IfInString, BatchDetail, Open Bracket
TempArray4:=1
IfInString, BatchDetail, Left To Right
TempArray5:=1
IfInString, BatchDetail, Delete All
TempArray6:=1
Else
Temp:=RegExMatch(BatchDetail,"([0-9]{1,2})", TempArray7)
FileName:=DeleteBrackets(FileName, TempArray1, TempArray2, TempArray3, TempArray4, TempArray5, TempArray6, TempArray7)
}
Else If BatchType=String Replacement
{
TempEx := """(.*?)"" With ""(.*?)"""
Temp:=RegExMatch(BatchDetail, TempEx, TempArray)
IfInString, BatchDetail, Replace All Occurrences
TempArray3:=1
IfInString, BatchDetail, Case Sensitive
StringCaseSense, ON
StringReplace, FileName, FileName, %TempArray1%, %TempArray2%, %TempArray3%
StringCaseSense, OFF
}
Else If BatchType=Insert Counter
{
TempEx := "([0-9]{1,2}) Digits Long, by ([0-9]{1,2}), At Position ([0-9]{1,2})"
Temp:=RegExMatch(BatchDetail, TempEx, TempArray)
IfInString, BatchDetail, Beginning
TempArray4:=1
IfInString, BatchDetail, Before
TempArray5:=1
IfInString, BatchDetail, After
TempArray6:=1
FileName:=InsertCounter(FileName, Counter, TempArray1, TempArray2, TempArray5, TempArray6, TempArray3, TempArray4)
}
Else If BatchType=Insert String
{
TempEx := """(.*)"" At Position ([0-9]{1,2})"
Temp:=RegExMatch(BatchDetail, TempEx, TempArray)
IfInString, BatchDetail, From Beginning
TempArray3:=1
FileName:=InsertString(FileName, TempArray1, TempArray2, TempArray3)
}
Else If BatchType=Character Deletion
{
Temp:=RegExMatch(BatchDetail, "Delete ([0-9]{1,2}) Characters", TempArray)
IfInString, BatchDetail, Characters From Position
{
TempArray2:=1
Temp:=RegExMatch(BatchDetail, "Position ([0-9]{1,2})", TempEx)
TempArray4:=TempEx1
IfInString, BatchDetail, From Beginning
TempArray5:=1
}
Else
{
IfInString, BatchDetail, Characters Before
TempArray3:=1
Temp:=RegExMatch(BatchDetail, """(.*)""", TempArray6)
StringReplace, TempArray6, TempArray6, ",, All ;"
}
FileName:=DeleteCharacter(FileName, TempArray1, TempArray2, TempArray3, TempArray4, TempArray5, TempArray6)
}
}
Return FileName
}
;=================================================
;=================Command Line====================
;=================================================
ProcessCommandLine:
SplitPath, A_ScriptName,,,, ScriptsName
INIFile:=ScriptsName ".ini"
IniRead, DefaultBatch, %INIFile%, Batch, DefaultBatch, %A_Space%
IniRead, SubFolder, %INIFile%, Settings, SubFolder, 0
If Not DefaultBatch
Return
NumOfFilesRenamed:=0
Loop, Parse, DefaultBatch, ?
IfInString, A_LoopField, Insert Counter
{
Temp3:=RegExMatch(Temp1, "([0-9]{1,2})", TempStart)
Counter:=TempStart-1
Break
}
Loop, %0%
{
Parameter:=%A_Index%
FileGetAttrib, test, %Parameter%
IfInString, test, D
ProcessFolder(Parameter, DefaultBatch, Counter, NumOfFilesRenamed, SubFolder)
Else
ProcessFile(Parameter, DefaultBatch, Counter, NumOfFilesRenamed)
}
MsgBox, Done!`n%NumOfFilesRenamed% Files Renamed!
Return
ProcessFolder(Folder, Batch, ByRef Counter, ByRef NumOfFilesRenamed, SubFolder)
{
Loop, %Folder%\*, 0, %SubFolder%
{
SplitPath, A_LoopFileName,,,, FileName
Loop, Parse, Batch, ?
FileName:=ProccessBatchString(A_LoopField, FileName, Counter)
NewFilePath:=A_LoopFileDir "\" FileName "." A_LoopFileExt
If !(A_LoopFileFullPath == NewFilePath)
{
If (A_LoopFileFullPath != NewFilePath) && FileExist(NewFilePath)
{
SplitPath, NewName,,, FileExt, FileName
Loop
{
NewFilePath := FullFilePath "\" FileName "_" A_Index "." FileExt
IfNotExist, %NewFilePath%
Break
}
}
FileMove, %A_LoopFileFullPath%, %NewFilePath%
NumOfFilesRenamed++
}
}
}
ProcessFile(GivenPath, Batch, ByRef Counter, ByRef NumOfFilesRenamed)
{
Loop %GivenPath%
File=%A_LoopFileLongPath%
SplitPath, File,, FilePath, FileExt, FileName
Loop, Parse, Batch, ?
FileName:=ProccessBatchString(A_LoopField, FileName, Counter)
NewFilePath:=FilePath "\" FileName "." FileExt
If !(File == NewFilePath)
{
If (File != NewFilePath) && FileExist(NewFilePath)
{
SplitPath, NewName,,, FileExt, FileName
Loop
{
NewFilePath := FullFilePath "\" FileName "_" A_Index "." FileExt
IfNotExist, %NewFilePath%
Break
}
}
FileMove, %File%, %NewFilePath%
NumOfFilesRenamed++
}
}
;=================================================
;===================Batch Tab=====================
;=================================================
AddToBatch:
Gui, 3: Submit, NoHide
If AddToNew
If StrLen(NewBatchName) != 0
Loop, Parse, ListOfBatchNames, |
{
If !A_LoopField
Continue
If (A_LoopField = NewBatchName)
{
Gui, 3:+OwnDialogs
Msgbox,, %A_Space%, "%NewBatchName%" Already Exist
Gui, 3:-OwnDialogs
Return
}
}
Else
{
Gui, 3:+OwnDialogs
Msgbox,, %A_Space%, The New Batch Must Have A Name
Gui, 3:-OwnDialogs
Return
}
GoSub, 3GuiClose
Gui 1:Default
GoSub, SaveCurrentBatch
If AddToExist
If CurrentBatch=%ExistBatchName%
{
GoSub, ActionToBatch
Return
}
Gui, ListView, BatchList
LV_Delete()
StringReplace, ListOfBatchNames, ListOfBatchNames, ||, |, All
GuiControl, -Redraw, BatchList
If AddToNew
{
ListOfBatchNames:=ListOfBatchNames NewBatchName "||"
If StoredBatches
StoredBatches:=StoredBatches "?" NewBatchName "?"
Else
StoredBatches:=NewBatchName "?"
LV_ModifyCol(1, "AutoHdr", NewBatchName)
}
Else
{
StringReplace, ListOfBatchNames, ListOfBatchNames, %ExistBatchName%|, %ExistBatchName%||
If ExistBatchName=Default
BatchString:=DefaultBatch
Else
BatchString:=ProcessStoredBatches(StoredBatches, "Load", ExistBatchName)
Loop, Parse, BatchString, ?
If A_LoopField
LV_Add("", A_LoopField)
LV_ModifyCol(1, "AutoHdr", ExistBatchName)
}
GuiControl, +Redraw, BatchList
GuiControl,, BatchNameList, |%ListOfBatchNames%
GoSub, ActionToBatch
Return
ActionToBatch:
Gui, Submit, NoHide
If ActionList=Spacing
{
If Not DelExtraSpace && Not DotToSpace && Not CommaToSpace && Not UnderToSpace
Return
BatchString := "Spacing: "
If DelExtraSpace
BatchString := BatchString "Delete Extra Spacing, "
If DotToSpace
BatchString := BatchString "Dot To Space, "
If CommaToSpace
BatchString := BatchString "Comma To Space, "
If UnderToSpace
BatchString := BatchString "UnderScore To Space, "
If SkipNumSeq && DotToSpace
BatchString := BatchString "Skip Number Sequences, "
StringTrimRight, BatchString, BatchString, 2
}
Else If ActionList=Case Correction
{
If CapFirst
BatchString := "Case Correction: Capitalize first word"
Else If CapAll
BatchString := "Case Correction: Capitalize Every Word"