ScriptStudent,
Your working dir, the root of your loop, is set at c:\
Your target dir is set at C:\AHKeyTest
So within your loop, you will read your target dir and check whether its content needs to be copied to itself. Luckily, the test should always turn negative, but this does not seem a clean approach.
Your loop recurses over your file system, and changes the value of the %copy_it% variable from the moment a positive test is detected. The loop happily continues, without ever resetting the value of %copy_it%, nor copying a file.
After your loop, you check whether there was any file in the filesystem that needed to be copied, and than you copy the last seen file.
You might want to try this one:
Code:
; Copy only files based on the modification date
SetWorkingDir, C:
var1 += -10, days
Target = c:\AHKeytest
FileRemoveDir, %target%, 1
FileCreateDir, %target%
Loop, %A_WorkingDir%\*.*, 0 , 1 ; Recurse into subfolders.
{
FileGetTime, time, %A_LoopFileLongPath%, M
if time < %var1%
{
StringMid, newfile, A_LoopFileLongPath, 3, 999 ;drop drive part, keep \
FileCopy, %A_LoopFileLongPath%, %target%%newfile%, 1 ; Copy with overwrite=yes
if ErrorLevel <> 0
MsgBox, Could not copy "%A_LoopFileLongPath%" to "%target%%newfile%".
}
}