0

I'm attempting to embed the current value of an AutoIt counter loop into a directory name. I'm running 1000 iterations of an analysis and need to ensure the output from the statistical software doesn't overwrite itself. Here's my code:

$counter = 0
Do
    FileCopy("C:\Users\Lambeezy\Documents\Folder\ReferentGroup.txt", "C:\Users\Lambeezy\Documents\DifferentFolder\"$counter")
    $counter = $counter + 1
Until $counter = 5
user4157124
  • 2,809
  • 13
  • 27
  • 42

2 Answers2

1

As per Documentation - Language Reference - Operators:

& Concatenates/joins two strings.

&= Concatenation assignment.

AutoIt allows concatenation of string to integer. Example using For...To...Step...Next loop:

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

Alternatively StringFormat() can be used:

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.

Community
  • 1
  • 1
user4157124
  • 2,809
  • 13
  • 27
  • 42
0

It's described in the language reference here: https://www.autoitscript.com/autoit3/docs/intro/lang_operators.htm

& Concatenates/joins two strings. e.g. "one" & 10 (equals "one10")

$counter = 0 
Do 
    FileCopy("C:\Users\Lambeezy\Documents\Folder\ReferentGroup.txt", "C:\Users\Lambeezy\Documents\DifferentFolder\" & $counter) 
    $counter = $counter + 1 
Until $counter = 5
sascha
  • 4,671
  • 3
  • 36
  • 54