Looping through a folder & passing filename as a variable

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
user1824
Posts: 29
Joined: 10 Sep 2021, 10:40

Looping through a folder & passing filename as a variable

Post by user1824 » 17 Sep 2021, 11:46

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!
colt
Posts: 291
Joined: 04 Aug 2014, 23:12
Location: Portland Oregon

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

Post by colt » 17 Sep 2021, 12:25

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.
User avatar
boiler
Posts: 16902
Joined: 21 Dec 2014, 02:44

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

Post by boiler » 17 Sep 2021, 12:34

Agree with colt. Use Loop, Files and the A_LoopFileFullPath built-in variable.
user1824
Posts: 29
Joined: 10 Sep 2021, 10:40

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

Post by user1824 » 17 Sep 2021, 13:33

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:
User avatar
boiler
Posts: 16902
Joined: 21 Dec 2014, 02:44

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

Post by boiler » 17 Sep 2021, 13:39

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.
user1824
Posts: 29
Joined: 10 Sep 2021, 10:40

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

Post by user1824 » 17 Sep 2021, 13:52

Thanks man, really appreciate your help, will try it out & see how it goes!
Post Reply

Return to “Ask for Help (v1)”