Page 1 of 1

Find Filename Using Wildcard and Variable

Posted: 07 Dec 2019, 18:15
by john68
I'm trying to use a combination of a wildcard and a variable to select a file (the first matching file found). As a simplified example:

Code: Select all

var := 1
		
		Loop, E:\xxjb\A\%InFolder%\*%var%.txt
		{
		
			SelectedFile := A_LoopFileName
	break
		}
	msgbox, %SelectedFile%
	}
In the "Loop" line, if I replace %var% with the actual value (1), it works fine.

Re: Find Filename Using Wildcard and Variable

Posted: 07 Dec 2019, 19:09
by boiler
What you showed works (once you remove the extraneous } and define a value for InFolder that makes it a valid file path. You probably have some other error in your non-simplified version. If you can show the code from the non-simplified version, then it may be possible to spot the problem. Using a wildcard and a variable is not the problem.

Re: Find Filename Using Wildcard and Variable

Posted: 08 Dec 2019, 00:20
by john68
Thank you, I did have an invalid file path due to a math calculation in the wrong place. Was easy to locate once you mentioned the potential problem.