AHK 循环文件和文件夹中通配符的使用

Usage of Wildcards in AHK Loop Files and Folders

我正在寻找一种更明确的方法来定义文件夹中文件的循环。以下面的循环为例。它正在寻找 text*.txt 个文件。但我想定义一个更具体的通配符搜索,可以找到 text1.txttextA.txt 等文件,但不能找到 text1 - COPY.txt

我不熟悉 AHK 通配符语法,但也许我正在寻找的内容可以使用正则表达式来解释,我正在寻找 "text.\.txt" ...第一个 . (点)匹配任何单个字符(与 "text.*\.txt" 相反,点星号是任何东西)

loop, % C:\Users\username\Downloads\text*.txt
  {
    ; do arbitrary tasks in loop.
  }

我假设 loop, % C:\Users\username\Downloads\text*.txt 是一个 打字错误 ,因为它实际上什至无法编译。您需要在表达式中的字符串周围加上引号,但我相信您已经知道了。

不过,您可能没有意识到您正在使用已弃用的旧文件循环。
切换到 modern file loop.

关于你的问题,我想说你能做的最好的事情就是在循环中进一步过滤。然后你也可以用你想要的任何方法过滤。
这是您提到的正则表达式的示例:

Loop, Files, % "C:\Users\username\Downloads\text*.txt"
    if (A_LoopFileName ~= "text.\.txt")
        MsgBox, % "This file passed the additional filter: " A_LoopFileName

如果您不熟悉 AHK 中的 ~= 运算符,它是 shorthand for RegExMatch()