 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Eleria
Joined: 09 May 2006 Posts: 90
|
Posted: Wed Jun 07, 2006 6:24 pm Post subject: [Smart Renamer] |
|
|
Hello once more.
After coding my [Anime Renamer] i felt like to do something better and ... not self based
Therefore....
I started the [Smart Renamer]
Basically you set up a template for the stuff you want to rename, for example
| Code: |
[%Anime%] %Team% #/*
|
This will create 2 edit box with a text (the one enclosed within %%) upon them.
And then another edit box for the counter ( represented by #)
After the slash comes the extention... to keep the old one just put *
It almost prepares coffee :p
Then you just have to drag drop files upon the window to start renaming them
Please post your comments. (Any of them !!! Flaming is allowed too >_< , well at least if the person has solid arguments)
THE CODE (Commented ^_^)
| Code: | #SingleInstance Off
SetBatchLines, -1
;-----------------------File Management------------------------------
IfNotExist, Template
FileAppend, [Templates]`nTemp1=`%Example`% #/*, Template
Loop
{
IniRead, Temp%A_Index%, Template, Templates, Temp%A_Index%
IfEqual, Temp%A_Index%, ERROR, Break
}
;--------------------------------------------------------------------
Str := Temp1 ;Take the first template as default
Err2 = No start number
Menu, FileMenu, Add, &Templates, Templates
Menu, FileMenu, Add, E&xit, Exit
Menu, Menu, Add, &File, :FileMenu
Gui_Create:
Gui, 1:Default
Name =
Gui_Num = 0
Pos = 1
Loop, Parse, Str, /
If (A_Index & 1) ;Separate the string in string/extension
{
Loop, Parse, A_LoopField, `%
If (A_Index & 1)
Name := Name "|" A_LoopField ;Replace the percent enclosed stuff by pipes
Else
{
Gui_Num++ ;How many variables
Pos%A_LoopField% := A_Index ;Remember the variable position
Title%Gui_Num% := A_LoopField ;Remember the variable name
}
}
Else
Ext := A_LoopField ;Store the extension
StringTrimLeft, Name, Name, 1 ;Remove the heading pipe
Width := Gui_Num*100-8 ;Set the control positioning equation
Gui, 1:-SysMenu +AlwaysOnTop
Loop %Gui_Num% ;Create controls
{
Gui, Add, Text, x%Pos% y0 w50 h11, % Title%A_Index%
Gui, Add, Edit, x%Pos% y12 w90 h18 vText%A_Index%
Pos += 100
}
Gui, Menu, Menu
Gui, Add, Text, x1 y31 w50 h11 , Count
Gui, Add, Edit, x1 y50 w90 h18 Number v#
Gui, Show, h90 w%Width%, Smart Renamer
Return
GuiDropFiles:
Gui, Submit, Nohide ;Save the current vars
IfEqual, #,
{ ;The counter variable is empty
Loop, Parse, A_GuiControlEvent, `n ;Parse the file list
{
Line++
If (Line != 1)
{
Error(Err2)
Line = 0
Exit
}
}
Line = 0
}
List := A_GuiControlEvent ;Duplicate the list
Sort List, \ ;Sort the list
NName := Name ;Duplicate the string
Loop %Gui_Num%
{
StringReplace, NName, NName, |, % Text%A_Index% ;Replaces each pipe with the edit vlabel
}
NumLen := StrLen(#)
Zeroes = 0
Loop, Parse, # ;Counter is set with heading zeroes?
{
If !(A_LoopField = "0")
Break
Zeroes++
}
Loop, Parse, List, `n
{
If (Zeroes != 0)
{
Loop %Zeroes%
# = 0%#%
StringRight #, #, NumLen ;Keep as much chars as input (avoid 01 => 2)
}
StringReplace, FileName, NName, #, %#% ;Replace # with the counter
If # =
StringTrimRight, FileName, FileName, 1 ;Delete the tailing space if there is no counter
SplitPath, A_LoopField,, Dir, OExt
IfEqual, Ext, * ;Extension is not specified ?
{
Nxt := OExt
FileMoveDir, %A_LoopField%, %Dir%\%FileName% ;Rename Dir
}
Else
Nxt := Ext
FileMove, %A_LoopField%, %Dir%\%FileName%.%Nxt% ;Rename File
If ErrorLevel <> 0
Msgbox,, ERROR, Could not process file(s).
#++
}
Return
Error(ByRef Error_Text)
{
Gui, Submit
MsgBox,,ERROR, %Error_Text%
Gui, Show
}
Templates: ;Choose among templates
Gui, Destroy
Gui, 2:-SysMenu +AlwaysOnTop
Gui, 2:Default
Gui, 2:Add, ListView, NoSortHdr gChoose, Number|Content
Loop
{
IfEqual, Temp%A_Index%, ERROR, Break
LV_Add("", A_Index, Temp%A_Index%)
}
Gui, 2:Show,, Templates
Return
Choose:
WinGetPos, Cx, Cy,,, A
If A_GuiEvent = DoubleClick ;Double click = choose template
{
LV_GetText(RowNum, A_EventInfo, 1)
LV_GetText(RowContent, A_EventInfo, 2)
Str := Temp%RowNum% ;Set the string to be the choosen one
Gui, 2:Submit
Gosub, Gui_Create ;Recreate the gui with the newly got input
}
return
Exit:
ExitApp |
Future Improvements :
-A non-Ridiculous Gui (Almost Done :p)
-Load templates from files ? (Done)
-Maybe a menu to create and choose amongst the templates (Done)
I don't know.... anyway if it isn't that much usefull for other people than me i will not tweak it that much
Edit : Now reading from file and possibility to choose the wanted template.
Edit : 11/06/06 Now everything is working as expected (filels AND folders ) and code is commented
Edit : 03/07/06 Added error recognition / shortened the code ^_^[/code] _________________
Looking for a game/anime ost?
Last edited by Eleria on Wed Aug 02, 2006 3:19 pm; edited 14 times in total |
|
| Back to top |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6836 Location: France (near Paris)
|
Posted: Thu Jun 08, 2006 8:47 am Post subject: |
|
|
Uuh, I have no time to read it attentively, just a remark or two:
- What if I want Ext as extension? May seems silly, but I don't like restrictions... Perhaps use a forbidden character like * instead.
- Do you know the Transform, v, Deref, String command? It may save you some sweat... ^_^ _________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2") |
|
| Back to top |
|
 |
Eleria
Joined: 09 May 2006 Posts: 90
|
Posted: Thu Jun 08, 2006 9:00 am Post subject: |
|
|
Hi PhiLho
| Quote: | | Perhaps use a forbidden character like * instead |
Yeah good idea
| Code: | | Do you know the Transform, v, Deref, String command? It may save you some sweat |
Yeah i do know the transform command.
And as i can see in the manual the deref command is a special transform operation....
Is it the same as dereferencing in c#/c++ ?
If so then i can do
| Code: | | Transform, List, deref, %A_GuiControlEvent% |
Instead of
| Code: | | List = %A_GuiControlEvent% |
So i use less variables, is that what you think of ?
As i do not need to handle non printable characters .. why would i need to transform the strings ? please explain further  _________________
Looking for a game/anime ost? |
|
| Back to top |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6836 Location: France (near Paris)
|
Posted: Thu Jun 08, 2006 10:19 am Post subject: |
|
|
Example of use:
| Code: | Str = `%WTF`%`%BBQ`%`%Sauce`% #/AE
WTF = What the Furnace
BBQ = Boring bold quote
Sauce = Yes, thank you
num = 42
pos := InStr(Str, "/")
StringLeft template, Str, pos - 1
StringTrimLeft ext, Str, pos
StringReplace result, template, #, %num%
Transform result, Deref, %result%
MsgBox %template% => %result%.%ext%
| Of course, it needs some more tests (pos and ext values, etc.) but that's the spirit.
[EDIT] I don't know if it is usable, you still have to parse the string to know how many fields to display, their names... Sorry, it may not be usable. _________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2") |
|
| Back to top |
|
 |
Eleria
Joined: 09 May 2006 Posts: 90
|
Posted: Thu Jun 08, 2006 11:39 am Post subject: |
|
|
I just looked at your post... and ... it was a
Its so funny how i ALWAYS complicate simple things .....
Maybe i followed this too closely : "Why having hard time doing it the easy way when its simple to do it in a complicated way"
Anyway thank you again for pointing this out to me.
I will try to update the code with this damn simple alternative.... when i get some time.... _________________
Looking for a game/anime ost? |
|
| Back to top |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6836 Location: France (near Paris)
|
Posted: Thu Jun 08, 2006 12:14 pm Post subject: |
|
|
| Eleria wrote: | Its so funny how i ALWAYS complicate simple things .....
Maybe i followed this too closely : "Why having hard time doing it the easy way when its simple to do it in a complicated way" | Actually, I tend to work this way: I do complicate things, and when dust falls down, I take a view from a higher point and then think of ways to simplify my code, factorize stuff, etc.
Experience allows to reduce this tendency, but not that much.
And knowing well your programming language and system to find shortcuts helps too... ^_^ _________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2") |
|
| Back to top |
|
 |
Eleria
Joined: 09 May 2006 Posts: 90
|
Posted: Thu Jun 08, 2006 3:02 pm Post subject: |
|
|
A question on the flight :
When i do that :
| Code: | | Transform, List, deref, %A_GuiControlEvent% |
List now points to the address of %A_GuiControlEvent%
And it doesnt create another emplacement in the memory ... riiiiiight ? _________________
Looking for a game/anime ost? |
|
| Back to top |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6836 Location: France (near Paris)
|
Posted: Thu Jun 08, 2006 3:38 pm Post subject: |
|
|
Wrong... -_-
List will contain a copy of the string in A_GuiControlEvent with all occurences of %xxx% replaced by the content of the variable xxx.
To have the address of a variable, you can do:
list := &var
but you can't do much with this address, except accessing the numerical value of the character pointed at the address:
| Code: | len := StrLen(str)
addr := &str
Loop %len%
{
If (*addr = Asc("%"))
; Do something...
addr++
}
| That's the same thing as Loop Parse, with the bonus that you can jump forward or backward, stop and continue, etc. _________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2") |
|
| Back to top |
|
 |
Eleria
Joined: 09 May 2006 Posts: 90
|
Posted: Thu Jun 08, 2006 4:06 pm Post subject: |
|
|
Okay .... i got confused alot while i was learning C#, when i reached the pointer and struct chapters
And still have some problems with them
That is why sometime i have problems in ahk  _________________
Looking for a game/anime ost? |
|
| Back to top |
|
 |
Eleria
Joined: 09 May 2006 Posts: 90
|
Posted: Sun Jun 11, 2006 10:01 am Post subject: |
|
|
New code, works properly and new functionalities ^_^ _________________
Looking for a game/anime ost? |
|
| Back to top |
|
 |
Eleria
Joined: 09 May 2006 Posts: 90
|
|
| Back to top |
|
 |
vixay
Joined: 12 Jun 2008 Posts: 51
|
Posted: Fri Apr 03, 2009 8:13 am Post subject: What about dropdown boxes? |
|
|
What about dropdown boxes?
Can we do those? With defined options
and where do i save the template? I can't find the file...
also you need to put a comment/marker on the GUI saying, Drag & drop file here to rename according to your selected options... because it isn't intuitive...
Anyway your idea is great and it's the same I had just now for generating perfect filenames for specific uses.
I think another alternative to dragging and dropping files would also be good, like selecting the file/folder.
Also a preview of the final name would be great! For error checking sake... |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|