Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Using InputBox as a Prompt for Variables (inside a Renamer)



  • Please log in to reply
14 replies to this topic
bigdeoz
  • Members
  • 148 posts
  • Last active: Feb 04 2015 03:43 PM
  • Joined: 06 Sep 2013
[SOLVED] 10/12/2013
 
SEE LAST POST
 
[SOLVED] 10/12/2013
 
 
Hi guys!
 
I'm Deos and I'm new to the forum, I'm using ahk for the last 6 months and it's my first experience with programming (after ahk I had some experience with python3 e a little of prompt batch for win).
 
Now, to the task.
 
As excercise I decided to write a batch-mover/renamer and I had no problem with it until I decided that had to decide (sorry for the word game tongue.png) what information to insert into the name of the renamed files. For example the file could be renamed as "A_LoopFileName + A_Index + something" as well as "something + A_Index". I tried to put the variable inside an Inputbox so that i can type into that %A_Index%_file.%A_LoopFileExt% but it is not working since it doesn't recalculate the variable.
 
This is the code, if u wanna give me an hand..
...
InputBox, AddNam, How you wanna rename the files?, How you wanna rename the files? 
;(UP) this is the variable I'd like to put to something like " A_Index . "_" A_LoopFileName "." . A_LoopFileExt " without the external quotes
...
Loop, %SourcePattern%\%Fnam%.%Ftype%, %What%, %Recu%
{
    VarNam := AddNam ;with these I try to refresh the variable
    ...
    FileMove, %A_LoopFileFullPath%, %DestinationFolder%\%VarNam%, %DoOverwrite%
    ;(UP) this is where it should work but it doesn't       
    ...
}
    ...
return

The fact is that if I put just one variable into the Inputbox, it is read and refresh but if I try to put more than one (as an expression) it is not working.
 
I'm tryin to go around this with a function, something like this
Join(sep, params*) 
{
    for index,param in params
        str .= param . sep
    return SubStr(str, 1, -StrLen(sep))
}
that can format the variable in the correct sintax (but still needs a parser (to be added) to split literal string from variables).
 
EDIT
 
edited the whole post to make it more readable and less time comsuming
 
Thank You for your time!

Edited by bigdeoz, 10 December 2013 - 11:30 AM.


bigdeoz
  • Members
  • 148 posts
  • Last active: Feb 04 2015 03:43 PM
  • Joined: 06 Sep 2013

Up§? 



Jackie Sztuk _Blackholyman
  • Spam Officer
  • 3757 posts
  • Last active: Apr 03 2016 08:47 PM
  • Joined: 28 Feb 2012
welcome happy.png

maybe something like this
 
InputBox, AddNam, How you wanna rename the files?, How you wanna rename the files? 

Loop, %SourcePattern%\%Fnam%.%Ftype%, %What%, %Recu%
{
    VarNam := AddNam . A_Index . "_" A_LoopFileName "." . A_LoopFileExt

    FileMove, %A_LoopFileFullPath%, %DestinationFolder%\%VarNam%, %DoOverwrite%
}
Hope it helps

if thats not it please give an example of the text you write in the inputbox and how you like it used
Helping%20you%20learn%20autohotkey.jpg?d

[AHK] Version. 1.1+ [CLOUD] DropBox ; Copy [WEBSITE] Blog ; About

bigdeoz
  • Members
  • 148 posts
  • Last active: Feb 04 2015 03:43 PM
  • Joined: 06 Sep 2013
For start, thank you for the help and for the welcoming ^ ^

To the task:

Your solution is fine and it was in my "latest stable" (or should I say just "working" lol) version of this script. BUT what if I want to choose how to combine the name's parts variables? As example, right now the name is VarNam := AddNam . A_Index . "_" A_LoopFileName "." . A_LoopFileExt what if I want to remove the old name and put a new string as name after the Index? VarNam should become something like VarNam := A_Index . "_" AddNam "." . A_LoopFileExt <--[this could be removed after all by using another variable as extension, so I can choose to change it in case] but I want to do this from the Inputbox. And If I type A_Index . "_" AddNam "." . A_LoopFileExt into the InputBox it is read as a literal string, while if I just write A_Index or another variable by itself it is read correctly.

Maybe I need to create a function or an array with the variables as params so I can call and organize those freely.

Any idea?

TY again :)

D.z

bigdeoz
  • Members
  • 148 posts
  • Last active: Feb 04 2015 03:43 PM
  • Joined: 06 Sep 2013
OT


btw I tried to reply like 45 times to this post with the Marble Theme and never goes, now with plain text and IP.Board I managed to do it so I'll edit that for viewing necessity as sooon as the forum will let me do it ^^

D.z

bigdeoz
  • Members
  • 148 posts
  • Last active: Feb 04 2015 03:43 PM
  • Joined: 06 Sep 2013
up?

bigdeoz
  • Members
  • 148 posts
  • Last active: Feb 04 2015 03:43 PM
  • Joined: 06 Sep 2013
up?

Jackie Sztuk _Blackholyman
  • Spam Officer
  • 3757 posts
  • Last active: Apr 03 2016 08:47 PM
  • Joined: 28 Feb 2012
You may need to re-write what your problem is as im not sure i get it... but i'd like to help
Helping%20you%20learn%20autohotkey.jpg?d

[AHK] Version. 1.1+ [CLOUD] DropBox ; Copy [WEBSITE] Blog ; About

bigdeoz
  • Members
  • 148 posts
  • Last active: Feb 04 2015 03:43 PM
  • Joined: 06 Sep 2013
Hi again,

In the case you pointed [[I'd like to quote but I'm still having this problem with the forum]], VarNam is "prefixed", the name will always have that structure. I'd like to find a solution that can let me change that structure without editing the code itself. As an example, if I want to batch-rename all the jpeg files in my documents folder as 1asd.jpeg, 2asd.jpeg, etc. etc. I should change VarNam into := A_Index . AddNam (aka a string of text, "asd" in this case) "." . A_LoopFileExt

Now, my problem is that I want to change it by the InputBox (" InputBox, VarNam, ... " as example) but it doesn't work for more than one variable, or, more precisely, it doesn't access the vars contents if there are more than one in the string (VarNam in this case).

So, the solution is to make the output of the Inputbox as a literal string then pass it into another variable during the loop so that it recalculates the variables contents (and I haven't been able to make it work) OR if there is a way to pass more than one variable (content) from the inputbox (aka make it read an expression such VarNam in your example).

To clarify try this example:

InputBox, OutVar,
Loop,
{
MsgBox % %OutVar%
}

If you write " A_Index " into Inputbox (without quotes), the message box will display 1, 2, 3, etc. etc. BUT if you try to write "A_Index . ErrorLevel " then the message box pops an error.

Am I been clear? Hope so! ^ ^

TY!

D.z

bigdeoz
  • Members
  • 148 posts
  • Last active: Feb 04 2015 03:43 PM
  • Joined: 06 Sep 2013
up?

bigdeoz
  • Members
  • 148 posts
  • Last active: Feb 04 2015 03:43 PM
  • Joined: 06 Sep 2013

Up?



hd0202
  • Members
  • 709 posts
  • Last active: Feb 14 2016 08:05 PM
  • Joined: 13 Aug 2006
✓  Best Answer

Another post brought the "Transform" command with the "deref" option to my mind. It lead me to the following suggestion:

sys = a_index,a_filename,errorlevel ; add others
loop, 2
{
inputbox, var, test, enter,,,,,,,, a_index . errorlevel
msgbox, % transformer(var)
}
exitapp

transformer(txt)
{
global sys
var := txt
loop,parse, sys, `,
{
stringreplace, var, var, %a_loopfield%, "`%%a_loopfield%`%", all
}
transform, var2, deref, %var%
stringreplace, var2, var2, ",, all
stringreplace, var2, var2, % " . ",, all
return var2
}

Hubert



bigdeoz
  • Members
  • 148 posts
  • Last active: Feb 04 2015 03:43 PM
  • Joined: 06 Sep 2013

Hi!

 

Thank you for your answer and sorry for the late response.

 

I was studying the case you proposed and I think I could work with it, I need to try it first. I'll let you know, but at first sight it seems that I could just process (with deref) the inputbox output var to make it work without the stringreplace process in the function (btw I have some ideas).

 

I'll response next week ;)

 

TY again



bigdeoz
  • Members
  • 148 posts
  • Last active: Feb 04 2015 03:43 PM
  • Joined: 06 Sep 2013

Haven't had much time to explore but I was wondering if it is "better" to use a RegExReplace expression (something like "\x25\b" where x25 is hex fo "%" and will find any "left side" occurrencies) instead of stringreplace, var, var, %a_loopfield%, "`%%a_loopfield%`%", all.

 

I'll try to come up with something more "entire" and we'll see, I guess.

 

TY



bigdeoz
  • Members
  • 148 posts
  • Last active: Feb 04 2015 03:43 PM
  • Joined: 06 Sep 2013

I'll add "solved" to the title, Hd0202 had the solution. Apart of the syntax I'd like to give to this "input command", the "trasform, deref" is the solution to the thread problem.

 

btw I managed to create the parser of my own but I found myself having by the hands a personal function which does exactly what "deref" does, with basically the same performance. 

 

Just to clarify for eventually others, follow this example:

InputBox, var, test, enter,,,,,,,, `%a_index`% . "string_test" . `%errorlevel`%
Loop,
{
MsgBox % var
transform, var2, deref, %var%
MsgBox % var2
}
return 

notice that the syntax of dots and quotes is useless, so the correct syntax in this case for var is `%A_index`% string_test `%ErrorLevel`%

 

also notice that the grave accent is needed ONLY if you put that command as a parameter of InputBox, if you have to write it into the InputBox you have to omit those accents(--> %A_index% string_test %ErrorLevel% <--).

 

 

Thank to everybody for help, especially to HD0202 ^^

 

Best Regards.

 

D.z