Need Help Writing filename

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Legion26
Posts: 3
Joined: 27 May 2021, 04:23

Need Help Writing filename

27 May 2021, 04:57

Good day

I don't have a lot of coding experience and I placed this together with some googling and it was working fine but now I would like to write my var number in front of the file name.

I added line 22 and line 31 and it doesn't want to write the var name in front of the filename can anyone tell me why it's not working and maybe show me how I can get it working. :D
fileName := var + "_" + fileName
Spoiler
gregster
Posts: 9001
Joined: 30 Sep 2013, 06:48

Re: Need Help Writing filename

27 May 2021, 06:48

+ is not used as a concatenation operator in AHK.

In AHK, in expression mode, you can do either of these:

Code: Select all

fileName := var "_" fileName
; or 
fileName := var . "_" . fileName
See https://www.autohotkey.com/docs/Variables.htm#concat for more details.
Legion26
Posts: 3
Joined: 27 May 2021, 04:23

Re: Need Help Writing filename

29 May 2021, 02:35

gregster wrote: + is not used as a concatenation operator in AHK.

In AHK, in expression mode, you can do either of these:

Code: Select all

fileName := var "_" fileName
; or 
fileName := var . "_" . fileName
See https://www.autohotkey.com/docs/Variables.htm#concat for more details.
I tried this but it still doesn't write the var number in front of my filename
gregster
Posts: 9001
Joined: 30 Sep 2013, 06:48

Re: Need Help Writing filename

29 May 2021, 03:46

Yes, it does:

Code: Select all

var := 32395
filename := "helloworld.txt"
fileName := var "_" fileName
msgbox % filename

var++
filename := "anotherfile.txt" 
fileName := var . "_" . fileName
msgbox % filename
But it looks like you are overwriting the result with the following line SplitPath, url, fileName, at least in your else-branch... perhaps you want to switch these lines?
Legion26
Posts: 3
Joined: 27 May 2021, 04:23

Re: Need Help Writing filename

15 Jun 2021, 07:21

gregster wrote:
29 May 2021, 03:46
Yes, it does:

Code: Select all

var := 32395
filename := "helloworld.txt"
fileName := var "_" fileName
msgbox % filename

var++
filename := "anotherfile.txt" 
fileName := var . "_" . fileName
msgbox % filename
But it looks like you are overwriting the result with the following line SplitPath, url, fileName, at least in your else-branch... perhaps you want to switch these lines?
I figured out what was wrong with the code :D the var was cleared when I entered the if function I just made the var a Global and it all works now

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: aitaixy, Anput, dangoscrub, Google [Bot], joedf, Nerafius and 170 guests