【问题标题】:Embed value of counter loop within a directory name在目录名称中嵌入计数器循环的值
【发布时间】:2015-05-14 18:52:51
【问题描述】:

我正在尝试将 AutoIt 计数器循环的当前值嵌入到目录名称中。我正在运行 1000 次分析迭代,需要确保统计软件的输出不会覆盖自身。这是我的代码:

$counter = 0
Do
    FileCopy("C:\Users\Lambeezy\Documents\Folder\ReferentGroup.txt", "C:\Users\Lambeezy\Documents\DifferentFolder\"$counter")
    $counter = $counter + 1
Until $counter = 5

【问题讨论】:

    标签: autoit


    【解决方案1】:

    这里的语言参考中有描述:https://www.autoitscript.com/autoit3/docs/intro/lang_operators.htm

    & 连接/连接两个字符串。例如"one" & 10(等于“one10”)

    $counter = 0 
    Do 
        FileCopy("C:\Users\Lambeezy\Documents\Folder\ReferentGroup.txt", "C:\Users\Lambeezy\Documents\DifferentFolder\" & $counter) 
        $counter = $counter + 1 
    Until $counter = 5
    

    【讨论】:

      【解决方案2】:

      根据Documentation - Language Reference - Operators

      & 连接/连接两个字符串。

      &= 串联赋值。

      AutoIt allows 字符串到整数的连接。使用For...To...Step...Next 循环的示例:

      Global Const $g_iMax     = 5
      Global Const $g_sPathSrc = 'C:\Users\Lambeezy\Documents\Folder\ReferentGroup.txt'
      Global Const $g_sPathDst = 'C:\Users\Lambeezy\Documents\DifferentFolder\'
      Global       $g_sPathCur = ''
      
      For $i1 = 1 To $g_iMax
      
          $g_sPathCur = $g_sPathDst & $i1
      
          FileCopy($g_sPathSrc, $g_sPathCur)
      
      Next
      

      也可以使用StringFormat()

      Global Const $g_iMax     = 5
      Global Const $g_sPathSrc = 'C:\Users\Lambeezy\Documents\Folder\ReferentGroup.txt'
      Global Const $g_sPathDst = 'C:\Users\Lambeezy\Documents\DifferentFolder\%s'
      Global       $g_sPathCur = ''
      
      For $i1 = 1 To $g_iMax
      
          $g_sPathCur = StringFormat($g_sPathDst, $i1)
      
          FileCopy($g_sPathSrc, $g_sPathCur)
      
      Next
      

      Related.

      【讨论】:

        猜你喜欢
        • 2016-07-25
        • 2020-09-27
        • 2020-10-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-07-01
        • 2013-03-27
        相关资源
        最近更新 更多