Hello, i am trying to make a simple script that copy everything from a volume/path to another.
I managed to, but it copies all inside a directory, also all the single files (not directories) in the source are copied into the root of the destination directory AND inside the copy of a source directory, generated inside destination path.
basically:
C:\test1
C:\test1\dir1
C:\test1\file.txt
will become:
D:\test2\test1
D:\test2\dir1
D:\test2\test1\file.txt
D:\test2\file.txt
instead of:
D:\test2\dir1
D:\test2\file.txt
what i am doing wrong?
Code:
#NoEnv
SendMode Input
#SingleInstance force
SetWorkingDir %A_ScriptDir%
;
FileSelectFolder, SourceFolder, , 3, CHOOSE SOURCE
if SourceFolder =
return
FileSelectFolder, TargetFolder, , 3, CHOOSE DESTINATION
if TargetFolder =
return
MsgBox, 4, , The contents of "%SourceFolder%" will be copied into "%TargetFolder%"?
IfMsgBox, No
return
SplitPath, SourceFolder, SourceFolderName
;
ErrorCount := CopyFilesAndFolders(SourceFolder, TargetFolder)
if ErrorCount <> 0
MsgBox %ErrorCount% files/folders could not be copied.
CopyFilesAndFolders(SourcePattern, DestinationFolder, DoOverwrite = false)
{
FileCopy, %SourcePattern%, %DestinationFolder%, %DoOverwrite%
ErrorCount := ErrorLevel
Loop, %SourcePattern%, 2
{
FileCopyDir, %A_LoopFileFullPath%, %DestinationFolder%\%A_LoopFileName%, %DoOverwrite%
ErrorCount += ErrorLevel
if ErrorLevel
MsgBox Could not copy %A_LoopFileFullPath% into %DestinationFolder%.
}
return ErrorCount
}
exitapp