Using RegExMatch on file obtained from Loop Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
jarhead
Posts: 149
Joined: 09 Sep 2020, 12:43

Using RegExMatch on file obtained from Loop

16 Apr 2021, 14:14

I have a folder of files. In this folder, I need to obtain the name of the one Excel spreadsheet (*.xlsx). The name of the spreadsheet will change depending on when the script I'm trying to create runs so I'm using Loop to obtain the file name. Although the name of the spreadsheet will change, it will always be named using Last Name, First Name File 4-16-2021 so, for example, Smith, John File 4-16-2021.

Once the Loop obtains the file name, I'm attempting to run RegExMatch on A_LoopFileName to obtain just the Smith, John portion of the file name. I'm using the following regex successfully in other scripts that returns the Smith, John portion of the file name:

Code: Select all

.+\\\K.+?, \w+
Long story short, the following script does not work. It is breaking down at the RegExMatch portion of the script as a MsgBox returns nothing when attempting to use the newly created VName variable.

So when I type ;ca and hit space, it should insert the following text → New File Created - Smith, John

Any help is appreciated.

Code: Select all

:o:;ca::
Loop, Files, %A_Desktop%\MyFolder\*.xlsx
RegExMatch(A_LoopFileName, ".+\\\K.+?, \w+", VName)
SendInput, {Text}New File Created - %VName%
return
User avatar
boiler
Posts: 16902
Joined: 21 Dec 2014, 02:44

Re: Using RegExMatch on file obtained from Loop  Topic is solved

16 Apr 2021, 14:49

Code: Select all

FileName := "Smith, John File 4-16-2021.xlsx"
RegExMatch(FileName, ".*(?= File \d+-\d+-\d+\.\w+)", VName)
MsgBox, New File Created - %VName%
User avatar
mikeyww
Posts: 26856
Joined: 09 Sep 2014, 18:38

Re: Using RegExMatch on file obtained from Loop

16 Apr 2021, 14:55

Try:

Code: Select all

RegExMatch(A_LoopFileName, ".+(?= File [\d-]+)", VName)
Edit: (Followed @boiler, similar idea)
jarhead
Posts: 149
Joined: 09 Sep 2020, 12:43

Re: Using RegExMatch on file obtained from Loop

16 Apr 2021, 15:01

boiler wrote:
16 Apr 2021, 14:49

Code: Select all

FileName := "Smith, John File 4-16-2021.xlsx"
RegExMatch(FileName, ".*(?= File \d+-\d+-\d+\.\w+)", VName)
MsgBox, New File Created - %VName%
Works great! Thanks.
jarhead
Posts: 149
Joined: 09 Sep 2020, 12:43

Re: Using RegExMatch on file obtained from Loop

16 Apr 2021, 15:02

mikeyww wrote:
16 Apr 2021, 14:55
Try:

Code: Select all

RegExMatch(A_LoopFileName, ".+(?= File [\d-]+)", VName)
Edit: (Followed @boiler, similar idea)
Also works. Thanks!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], jomaweb, mikeyww and 131 guests