I want to synchronize two folders, it is a one-way image copy.
What commands is used to execute in AHK?
Is there a command for AHK to synchronize folders?
Re: Is there a command for AHK to synchronize folders?
You could:
1. Loop, Files
2. See if the file exists in the other directory.
2.a. If not, copy it.
2.b. If so, FileGetSize; if newer, copy with overwrite.
3. If mirroring: loop through files in the target directory, recycling files that do not exist in the source.
A different approach for a mirror is to recycle the entire target directory, and then copy the source directory to the target directory. This ignores the possibility that the target directory might contain newer files.
Adjust the approach according to what you need to do with newer files, orphan files, etc.
Robocopy can handle just about every situation easily.
1. Loop, Files
2. See if the file exists in the other directory.
2.a. If not, copy it.
2.b. If so, FileGetSize; if newer, copy with overwrite.
3. If mirroring: loop through files in the target directory, recycling files that do not exist in the source.
A different approach for a mirror is to recycle the entire target directory, and then copy the source directory to the target directory. This ignores the possibility that the target directory might contain newer files.
Adjust the approach according to what you need to do with newer files, orphan files, etc.
Robocopy can handle just about every situation easily.
Re: Is there a command for AHK to synchronize folders?
Thanks.
Doesn’t it take time to judge the newness of the file?If so, FileGetSize; if newer, copy with overwrite
Re: Is there a command for AHK to synchronize folders?
You are absolutely right, as every command that is executed does indeed require time. This applies not only to AHK but also Robocopy, commercial synchronizers, and all programs, for that matter. With a solid-state disk, many of these times are quite short and hardly noticeable with small numbers of files. You can time your script to judge whether the time is acceptable, or compare times with different approaches. A_TickCount can be used to mark the time. You can then subtract values as needed.
I meant to indicate using FileGetTime, rather than size, though some people prefer to use the size to gauge certain differences. For me, well, size is just not the highest priority....
I meant to indicate using FileGetTime, rather than size, though some people prefer to use the size to gauge certain differences. For me, well, size is just not the highest priority....
Re: Is there a command for AHK to synchronize folders?
I've had good luck with RoboCopy which comes with most versions of Windows out of the box. /mir is the option to "mirror" two directories
https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/robocopy
You can drive it with ahk using RunWait or similar.
https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/robocopy
You can drive it with ahk using RunWait or similar.
Code: Select all
Path_Source := "C:/Your folder path"
Path_Destination := "C:/Your folder path"
RunWait, %comspec% /c Robocopy "%Path_Source%" "%Path_Destination%" *.* /MIR /R:1,,hide
Re: Is there a command for AHK to synchronize folders?
Thanks a lot. It solve the problem.
Re: Is there a command for AHK to synchronize folders?
by the way ,
what is the mean of "*.*"?
Code: Select all
RunWait, %comspec% /c Robocopy "%Path_Source%" "%Path_Destination%" *.* /MIR /R:1,,hide
Re: Is there a command for AHK to synchronize folders?
Microsoft wrote: Specifies the file or files to be copied. Wildcard characters (* or ?) are supported. If you don't specify this parameter, *.* is used as the default value.
Re: Is there a command for AHK to synchronize folders?
Thanks for reply.
Who is online
Users browsing this forum: mikeyww and 204 guests