Page 1 of 1

Looping through a folder & passing filename as a variable

Posted: 17 Sep 2021, 11:46
by user1824
I'm here to ask for suggestion, right now I've written a script to:
1. open an application,
2. import a file & do some manipulation on that file.

And I've a folder containing alot of files, I want to iterate through this folder and pickup 1 file at a time & send this file name to the above mentioned ahk script.

Approach 1: Write a python script looping through the folder & passing filename as a variable to that script.

Approach 2: Writing another ahk script looping through the folder & passing filename as a variable to that script.

Approach 3: Editing the present ahk script to add a loop at the top & then putting all the commands within the scope of that loop.

FYI, I'm a python developer trying my hands on ahk for the first time, please suggest something!

Re: Looping through a folder & passing filename as a variable

Posted: 17 Sep 2021, 12:25
by colt
I would do #3 just to keep everything together. However, if your script is robust you could do #2 and do your file manipulations in parallel.

Re: Looping through a folder & passing filename as a variable

Posted: 17 Sep 2021, 12:34
by boiler
Agree with colt. Use Loop, Files and the A_LoopFileFullPath built-in variable.

Re: Looping through a folder & passing filename as a variable

Posted: 17 Sep 2021, 13:33
by user1824
Okay so for a loop in ahk, I'm supposed to use {} or indentation to put code within the loop?
Sorry if I'm being too noob. :shifty:

Re: Looping through a folder & passing filename as a variable

Posted: 17 Sep 2021, 13:39
by boiler
With AHK, indentation is for visualization only. Use { } to identify code blocks as you described. An exception is if the loop only contains one line following the loop statement, then no { } are necessary.

See {…} (block) for more details on this.

Re: Looping through a folder & passing filename as a variable

Posted: 17 Sep 2021, 13:52
by user1824
Thanks man, really appreciate your help, will try it out & see how it goes!