代码之家  ›  专栏  ›  技术社区  ›  wetin

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

  •  0
  • wetin  · 技术社区  · 6 年前

    text*.txt 文件夹。但是我想定义一个更具体的通配符搜索,它可以找到诸如 text1.txt , textA.txt text1 - COPY.txt

    我不熟悉AHK通配符语法,但也许我要找的东西可以用regex解释,我正在寻找 "text.\.txt" ... 第一个呢 . (点)匹配任何单个字符(与 "text.*\.txt" 其中点星号是任何东西)

    loop, % C:\Users\username\Downloads\text*.txt
      {
        ; do arbitrary tasks in loop.
      }
    
    1 回复  |  直到 6 年前
        1
  •  1
  •   0x464e    6 年前

    我假设 loop, % C:\Users\username\Downloads\text*.txt 曾经是 ,因为这根本无法编译。表达式中的字符串需要引号,但我相信您已经知道了。

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

    关于你的问题,我想说你能做的最好的就是在循环中进一步过滤。然后你也可以用任何你想要的方法过滤。
    下面是您提到的regex示例:

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

    ~= shorthand for RegExMatch() .