Loop files in specified folder and perform action on individual files Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Bones23
Posts: 5
Joined: 29 Sep 2017, 04:00
Location: Gloucester, UK

Loop files in specified folder and perform action on individual files

20 Nov 2017, 06:57

HI

Sorry if I'm being dense here, I've searched the forums and looked at the help pages and am struggling to work this out.

The scenario: I have a list of files in a folder which I want to individually open, perform an action, then close again. My working code is:

FileSelectFolder, MyFolder ; Ask the user to pick a folder.
msgbox, %MyFolder%
Run, "C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe" "%MyFolder%\blank.pdf"

What I can't work out is how to loop the file names into a variable so instead of "%MyFolder%\blank.pdf" but I require "%MyFolder%\%MyFile% with each iteration of the loop amending the MyFile variable to the next file name in the folder

I am only just beginning to use AHK so any guidance would be greatly appreciated :)
Bones23
Posts: 5
Joined: 29 Sep 2017, 04:00
Location: Gloucester, UK

Re: Loop files in specified folder and perform action on individual files

20 Nov 2017, 07:28

Ok so I think I have now realised I don't need to assign the file name to a variable because the File-Loop will automatically do this for me: I have now amended my code to read:

FileSelectFolder, MyFolder ; Ask the user to pick a folder.
msgbox, %MyFolder%
Loop, Files, %MyFolder%
{
msgbox, %A_LoopFileFullPath%

;The below line works to open Adobe DC
Run, "C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe" "%MyFolder%\%A_LoopFileName%"
User avatar
Xeo786
Posts: 759
Joined: 09 Nov 2015, 02:43
Location: Karachi, Pakistan

Re: Loop files in specified folder and perform action on individual files  Topic is solved

20 Nov 2017, 07:31

Code: Select all

FileSelectFolder, MyFolder ; Ask the user to pick a folder.
Location := MyFolder "\*.pdf" ; loop thought pdf only
Loop, files, %Location%, R
	Run, %A_LoopFileFullPath%
see loop, files for examples
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory
Bones23
Posts: 5
Joined: 29 Sep 2017, 04:00
Location: Gloucester, UK

Re: Loop files in specified folder and perform action on individual files

20 Nov 2017, 09:38

Thanks Xeo,

I realised I was running an old version AHK and the syntax I was using from the help guide was for a more recent version. I have amended to the older versions syntax and is now working like a treat :)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot] and 230 guests