multi file copy functions in single AHK

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
drewjbx1
Posts: 2
Joined: 26 Oct 2020, 15:52

multi file copy functions in single AHK

26 Oct 2020, 16:44

I'm new to AHK and hoping to get some help...it would seem pretty simple what I am trying to do. I basically want to copy a couple of specific files to a backup folder... then copy all files/folders to the destination folder where I need it, overwrite is enabled. The first 2 lines of code I attempted this but it doesn't work.. its being ignored, do I need to add a pause or what am I missing.

Code: Select all

FileCopy, D:\Launchbox\Data\Playlists\Favorites.xml, D:\[ LB Data Backup ]\Data\Playlists\
FileCopy, D:\Launchbox\Data\Playlists\Family Favorites.xml, D:\[ LB Data Backup ]\Data\Playlists\

ErrorCount := CopyFilesAndFolders("D:\[ LB Data Backup ]\Data\*.*", "D:\Launchbox\Data")
if (ErrorCount != 0)
    MsgBox %ErrorCount% files/folders could not be copied.

CopyFilesAndFolders(SourcePattern, DestinationFolder, DoOverwrite = true)
; Copies all files and folders matching SourcePattern into the folder named DestinationFolder and
; returns the number of files/folders that could not be copied.
{
    ; First copy all the files (but not the folders):
    FileCopy, %SourcePattern%, %DestinationFolder%, %DoOverwrite%
    ErrorCount := ErrorLevel
    ; Now copy all the folders:
    Loop, %SourcePattern%, 2  ; 2 means "retrieve folders only".
    {
        FileCopyDir, %A_LoopFileFullPath%, %DestinationFolder%\%A_LoopFileName%, %DoOverwrite%
        ErrorCount += ErrorLevel
        if ErrorLevel  ; Report each problem folder by name.
            MsgBox Could not copy %A_LoopFileFullPath% into %DestinationFolder%.
    }
    return ErrorCount
}
User avatar
boiler
Posts: 16902
Joined: 21 Dec 2014, 02:44

Re: multi file copy functions in single AHK

26 Oct 2020, 16:49

Try without the \ on the end of the destination path. The name of the destination folder does not include a \ on the end. Make sure the destination folder exists.
User avatar
mikeyww
Posts: 26856
Joined: 09 Sep 2014, 18:38

Re: multi file copy functions in single AHK

26 Oct 2020, 16:56

Since your first line failed, this should be easy to debug. You can try the following to break it down.

Code: Select all

source = D:\Launchbox\Data\Playlists\Favorites.xml
target = D:\[ LB Data Backup ]\Data\Playlists
MsgBox, 0, Info, % "Source: " FileExist(source) "`n`nTarget: " FileExist(target)
You might see something like the following.
Attachments
image201026-1754-001.png
image201026-1754-001.png (2.38 KiB) Viewed 341 times
drewjbx1
Posts: 2
Joined: 26 Oct 2020, 15:52

Re: multi file copy functions in single AHK

26 Oct 2020, 17:23

boiler wrote:
26 Oct 2020, 16:49
Try without the \ on the end of the destination path. The name of the destination folder does not include a \ on the end. Make sure the destination folder exists.
That didn't seem to work
mikeyww wrote: Since your first line failed, this should be easy to debug. You can try the following to break it down.

Code: Select all

source = D:\Launchbox\Data\Playlists\Favorites.xml
target = D:\[ LB Data Backup ]\Data\Playlists
MsgBox, 0, Info, % "Source: " FileExist(source) "`n`nTarget: " FileExist(target)
You might see something like the following.
Yes I do see the same dialogue box... what exactly does that mean?
User avatar
Chunjee
Posts: 1418
Joined: 18 Apr 2014, 19:05
Contact:

Re: multi file copy functions in single AHK

26 Oct 2020, 18:25

One thing I did that worked well was used ahk to launch a CLI instance of RoboCopy (comes with Win 7, etc) https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/robocopy

It was something like Run, %COMSPEC% /c Robocopy %fromDir%, %destinationDir%, %options%


It was a little more robust than ahk trying to copy-paste files. Since it was over a network connection it needed some retry options built in.
User avatar
mikeyww
Posts: 26856
Joined: 09 Sep 2014, 18:38

Re: multi file copy functions in single AHK

26 Oct 2020, 18:35

I use Robocopy routinely, too. It works well and quickly, and also has built-in options to update files while not overwriting newer ones. The console display can be handy as well. ComSpec might not always be necessary; Robocopy can be found at %A_WinDir%\System32\Robocopy.exe.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: mikeyww and 231 guests