Page 1 of 1

Loop, Files with If statements. Need help with file pattern.

Posted: 10 Apr 2019, 20:07
by KilliK
Hello.
I have created a script with the Loop,Files command which scans a folder for all its files and depending on the ext/name of each file, it processes it accordingly.
I am doing only one Loop and use an if statement for each situation. Most of the if statements have this syntax:

Code: Select all

if (A_LoopFileExt in %File_Types%)
which works fine.

But I dont know how to write the if statement for the files with filename which conform to either of the two pattern criteria:

SelectedText*.txt
the * here is a random number

panel-*-image-*
the first * is a random number, the second * is random letters,numbers and characters. it also deosnt have an extension.

I know I can use two loops with their own file patterns and look specifically for those files, but I want to avoid that since I am already doing one Loop for all files.

How do I code this, do I use contains, InStr, regex, etc?

Re: Loop, Files with If statements. Need help with file pattern.  Topic is solved

Posted: 10 Apr 2019, 20:23
by Osprey
Try doing If(RegExMatch(A_LoopFileName, "SelectedText.*.txt")) and If(RegExMatch(A_LoopFileName, "panel-.*-image-.*")). .* in a RegEx pattern is a wildcard.

Re: Loop, Files with If statements. Need help with file pattern.

Posted: 10 Apr 2019, 21:19
by KilliK
that did it, thank you very much for your help.