Basic question (loop)

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
-Elaphe-
Posts: 75
Joined: 24 Dec 2020, 13:24

Basic question (loop)

Post by -Elaphe- » 09 Jun 2023, 15:22

I'm trying to modify a script I have that looks if a file is present in a set of folders (also comparing sizes, etc). I have it working but the code is repeated for every folder (something like ifexist, %folder1%\file.jpg...) which are defined as folder1, folder2, etc. So, to prevent the repetion of the code for the 15 folders, I've thought I could make a loop. However, I don't know how to change the number which is part of the variable. I think that my stupid code (which of course doesn't work) makes it clear what I'm trying to do.

Code: Select all

folder1=c:
folder2=d:
folder3=e:
...
folder15=z:

loop, 15
{
ifexist, %folder%%a_index%\file.jpg
...
}

kintar0e
Posts: 41
Joined: 05 Mar 2019, 07:32

Re: Basic question (loop)

Post by kintar0e » 09 Jun 2023, 16:16

Code: Select all

FFile := {"folder1":"C:\Temp","folder2":"D:\Drivers","folder3":"e:","folder4":"z:" }
F1::
	for k,v in FFile
	{
		MsgBox, % k " - " v
	}
Return

-Elaphe-
Posts: 75
Joined: 24 Dec 2020, 13:24

Re: Basic question (loop)

Post by -Elaphe- » 09 Jun 2023, 16:55

It seems what I'm dealing with is called dynamic variables.

After some tests, this appears to be successful:

Code: Select all

loop, 15
{
foldersearch := % folder%a_index%
ifexist, %foldersearch%\test.jpg
...

Post Reply

Return to “Ask for Help (v1)”