Link to original code: https://www.autohotkey.com/docs/commands/FileCopy.htm
The version with simplified directory names (Foo and Bar):
Code: Select all
; The following example copies all files and folders inside a folder to a different folder:
ErrorCount := CopyFilesAndFolders("C:\Foo\*.*", "C:\Bar")
if (ErrorCount != 0)
MsgBox %ErrorCount% files/folders could not be copied.
CopyFilesAndFolders(SourcePattern, DestinationFolder, DoOverwrite = false)
; 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
}
Code: Select all
Foo\
|-- Folder 1\
|-- Folder 2\
|-- File 1.txt
|-- File 2.txt
Instead, only the directories are copied. To copy the files you will need to run this script twice.
AHK version 1.1.30.03. Is there some error/bug in this example?