Exit script after 40mins of file copying

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
marypoppins_1
Posts: 94
Joined: 28 Oct 2020, 02:58

Exit script after 40mins of file copying

Post by marypoppins_1 » 26 Nov 2022, 09:12

Hey, I am creating code to be run in intervals of 40 minutes to copy folders and files on the drive. overwrite is off so that if a file / folder is already in destination it won't waste time again copying it. can someone check if my code is able to copy files and also exit out of the script after 40min of running the hotkey?
thanks in advance

Code: Select all

^numpad1::  
Gosub, exittymode
ErrorCount2 := CopyFilesAndFolders("D:\*.*", "C:\Users\GSAB\Documents\Temp1")
if (ErrorCount2 != 0)
    return
Return


exittymode:
sleep 2400000
ExitApp
return


CopyFilesAndFolders(SourcePattern, DestinationFolder, DoOverwrite = false)
{
    FileCopy, %SourcePattern%, %DestinationFolder%, %DoOverwrite%
    ErrorCount1 := ErrorLevel
    Loop, %SourcePattern%, 2  
        FileCopyDir, %A_LoopFileFullPath%, %DestinationFolder%\%A_LoopFileName%, %DoOverwrite%
        ErrorCount1 += ErrorLevel
    }
    return ErrorCount1
}

User avatar
mikeyww
Posts: 26883
Joined: 09 Sep 2014, 18:38

Re: Exit script after 40mins of file copying

Post by mikeyww » 26 Nov 2022, 09:33

Why does the reader need to check? You cannot test your script by running it?

marypoppins_1
Posts: 94
Joined: 28 Oct 2020, 02:58

Re: Exit script after 40mins of file copying

Post by marypoppins_1 » 26 Nov 2022, 09:53

like i tried it and it's in the sleeping 40minute phase then it will close the script. what i want is the moment is starts copying, to start counting 40 minutes, and after 40 minutes shut down the script. does a setTimer fix the issue?

User avatar
mikeyww
Posts: 26883
Joined: 09 Sep 2014, 18:38

Re: Exit script after 40mins of file copying

Post by mikeyww » 26 Nov 2022, 10:08

Gosub:
Jumps to the specified label and continues execution until Return is encountered.
"Continues execution" means execution of the called subroutine, not the calling subroutine. The calling subroutine does not proceed until the Return happens.

Yes, instead of Gosub, use a SetTimer to determine when to ExitApp. This enables your hotkey subroutine to proceed.

marypoppins_1
Posts: 94
Joined: 28 Oct 2020, 02:58

Re: Exit script after 40mins of file copying

Post by marypoppins_1 » 26 Nov 2022, 10:26

thanks, i think i got it

Post Reply

Return to “Ask for Help (v1)”