 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
jined
Joined: 01 May 2008 Posts: 21
|
Posted: Thu Oct 29, 2009 12:39 pm Post subject: Total volume copy - troubleshoot |
|
|
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
|
Last edited by jined on Thu Oct 29, 2009 12:48 pm; edited 2 times in total |
|
| Back to top |
|
 |
aaffe
Joined: 17 May 2007 Posts: 1002 Location: Germany - Deutschland
|
Posted: Thu Oct 29, 2009 12:42 pm Post subject: |
|
|
| What do you mean by free files? |
|
| Back to top |
|
 |
jined
Joined: 01 May 2008 Posts: 21
|
Posted: Thu Oct 29, 2009 12:44 pm Post subject: |
|
|
| aaffe wrote: | | What do you mean by free files? |
files (not directories) that are in the root of the source |
|
| Back to top |
|
 |
aaffe
Joined: 17 May 2007 Posts: 1002 Location: Germany - Deutschland
|
Posted: Thu Oct 29, 2009 12:47 pm Post subject: |
|
|
So what do you want to do instead?
You have eg:
c: as Sourcefolder.
Dont you want to copy the files from C:, but them from c:\temp, c:\tmp etc. or what else? |
|
| Back to top |
|
 |
jined
Joined: 01 May 2008 Posts: 21
|
Posted: Thu Oct 29, 2009 12:49 pm Post subject: |
|
|
| aaffe wrote: | So what do you want to do instead?
You have eg:
c: as Sourcefolder.
Dont you want to copy the files from C:, but them from c:\temp, c:\tmp etc. or what else? |
all the contents of C:\source into, for example, to D:\source |
|
| Back to top |
|
 |
doyle
Joined: 14 Nov 2007 Posts: 325 Location: London, England
|
|
| Back to top |
|
 |
:?: Guest
|
Posted: Thu Oct 29, 2009 1:26 pm Post subject: |
|
|
| Code: | #NoEnv
FileSelectFolder, source, , 3
If !source
Return
FileSelectFolder, target, , 3
If !target
Return
Splitpath, source, sourceOut
Splitpath, target, targetOut
MsgBox, 36, Copy, Copy "%sourceOut%" to "%targetOut%"?
IfMsgBox, No
Return
FileCopyDir, %source%, %target%\%sourceOut%
If !ErrorLevel
MsgBox, 64, :), Done!
Else
MsgBox, 48, :( Error #1, Error copying "%sourceOut%" to "%targetOut%". |
 |
|
| Back to top |
|
 |
jined
Joined: 01 May 2008 Posts: 21
|
Posted: Thu Oct 29, 2009 1:31 pm Post subject: |
|
|
Yes for a directory copy, i know...
but don't works for copy a volume  |
|
| Back to top |
|
 |
:?: :?: Guest
|
Posted: Thu Oct 29, 2009 1:59 pm Post subject: |
|
|
| Code: | #NoEnv
FileSelectFolder, source, , 3
If !source
Return
FileSelectFolder, target, , 3
If !target
Return
Splitpath, source, sourceOut
Splitpath, target, targetOut
MsgBox, 36, Copy, Copy "%sourceOut%" to "%targetOut%"?
IfMsgBox, No
Return
; Copy Files
Loop, %source%\*.*
{
FileCopy, %A_LoopFileFullPath%, %target%
If ErrorLevel
{
MsgBox, 48, :( Error #1, Error copying "%source%\%A_LoopFileName%, to "%targetOut%".
ExitApp
}
}
; Copy Folders
Loop, %source%\*.*, 2
{
FileCopyDir, %A_LoopFileFullPath%, %target%\%A_LoopFileName%
If ErrorLevel
{
MsgBox, 48, :( Error #2, Error copying "%source%\%A_LoopFileName%, to "%targetOut%".
ExitApp
}
}
MsgBox, 64, :), Done!
|
 |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|