I have a script that I can't seem to get to work correctly no matter how many iterations I try. It seems like this should be simple and I am missing something somewhere. Any help would be appreciated.
OK, so I want to look at a folder (Folder1). If the folder contains any files, I want to copy those files to another folder (Folder2). If Folder1 is empty, I want to clear Folder2 to match. I set this up to run every second. Essentially I am trying to create a mirror image of Folder 1. However, the script I have below seems to work on the first pass only (If Folder1 is empty, it clears Folder2 and if Folder1 has content, it copies it to Folder2), but Folder2 does not cycle back and forth (Empty, Full, Empty, Full, etc.) as the condition of Folder1 cycles between empty & full. Can someone please show me where I went wrong here or provide a better alternative?
Code: Select all
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#Persistent
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#SingleInstance force
Gosub, CheckBatch
SetTimer, CheckBatch, 1000
CheckBatch:
{
Folder = [path of folder 1]
Folder1 = [path of folder 2]
Loop, Files, %Folder%\*.*, F
TotalSize += A_LoopFileSize
If TotalSize <= 0
FileDelete, %Folder1%\*.*
If TotalSize > 0
FileCopy, %Folder%, %Folder1%
}
return
Chris70