【问题标题】:loop within loop - detecting end of loop in autohotkey循环内循环 - 检测自动热键中的循环结束
【发布时间】:2013-03-01 01:13:10
【问题描述】:

假设我有一堆包含水果名称的文件名。我想根据一个充满参考文件的文件夹(包含水果名称、句号和甜点名称的虚拟 txt 文件)自动重命名它们。

apple.tart、grape.jelly、kiwi.cake、mango.icecream、banana.pudding、cherry.cobbler 等

我想选择所有要重命名的文件,并将它们拖到我的脚本上。

  1. 如果循环中的文件已经包含某个组合,例如“cherry.cobbler”,我只是希望丢弃虚拟文件,并且文件不应重命名为“cherry.cobbler.cobbler”

  2. 如果循环中的文件包含单词“kiwi”,我希望将其更改为包含“kiwi.cake”。

  3. 如果循环中的文件包含未列出的水果,我希望添加一个包罗万象的字符串。所以“kumquat”会变成“kumquat.nodessert”

给我带来麻烦的是条件#3。我似乎无法提出正确的语法来指定检查最后一个虚拟文件的时间。

这是一些伪代码

Loop %0%
{
   Path := %A_Index%
    Loop %Path%, 1
    LongPath = %A_LoopFileLongPath%    
    SplitPath LongPath, OutFileName, OutDir, OutExtension, OutNameNoExt, OutDrive


    Loop thru folder of fruit combos
         {
         Stringsplit filenames from fruit-combos folder into %fruit% and %dessert%

         If OutNameNoExt contains %fruit%.%dessert%
             {
             FileDelete fruit.combo dummyfile
             continue; skip to next file to rename
             )

         If OutNameNoExt contains %fruit%
             {
             FileDelete fruit.combo dummyfile
             StringReplace %fruit% with %fruit%.%dessert%
             continue; skip to next file to rename
             )

         If OutNameNoExt not contains fruit.combo AND all dummy files have been checked
             {
             StringReplace %fruit% with %fruit%.nodessert
             )
         }
    ; proceed with next selected file
    }

【问题讨论】:

    标签: autohotkey nested-loops


    【解决方案1】:

    将条件 3 放在内部循环之外,它似乎可以工作

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-11-16
      • 2021-01-31
      • 1970-01-01
      • 2022-11-27
      • 2021-11-09
      • 2019-11-10
      • 2015-03-13
      • 1970-01-01
      相关资源
      最近更新 更多