AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Total volume copy - troubleshoot

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
jined



Joined: 01 May 2008
Posts: 21

PostPosted: Thu Oct 29, 2009 12:39 pm    Post subject: Total volume copy - troubleshoot Reply with quote

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
View user's profile Send private message
aaffe



Joined: 17 May 2007
Posts: 1002
Location: Germany - Deutschland

PostPosted: Thu Oct 29, 2009 12:42 pm    Post subject: Reply with quote

What do you mean by free files?
Back to top
View user's profile Send private message
jined



Joined: 01 May 2008
Posts: 21

PostPosted: Thu Oct 29, 2009 12:44 pm    Post subject: Reply with quote

aaffe wrote:
What do you mean by free files?


files (not directories) that are in the root of the source
Back to top
View user's profile Send private message
aaffe



Joined: 17 May 2007
Posts: 1002
Location: Germany - Deutschland

PostPosted: Thu Oct 29, 2009 12:47 pm    Post subject: Reply with quote

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
View user's profile Send private message
jined



Joined: 01 May 2008
Posts: 21

PostPosted: Thu Oct 29, 2009 12:49 pm    Post subject: Reply with quote

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
View user's profile Send private message
doyle



Joined: 14 Nov 2007
Posts: 325
Location: London, England

PostPosted: Thu Oct 29, 2009 1:03 pm    Post subject: Reply with quote

See this: http://www.autohotkey.com/forum/viewtopic.php?t=50161

Enguneer(sp) helped me out with it.
Back to top
View user's profile Send private message Visit poster's website
:?:
Guest





PostPosted: Thu Oct 29, 2009 1:26 pm    Post subject: Reply with quote

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%".

Question
Back to top
jined



Joined: 01 May 2008
Posts: 21

PostPosted: Thu Oct 29, 2009 1:31 pm    Post subject: Reply with quote

Yes for a directory copy, i know...

but don't works for copy a volume Sad
Back to top
View user's profile Send private message
:?: :?:
Guest





PostPosted: Thu Oct 29, 2009 1:59 pm    Post subject: Reply with quote

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!

Question Question
Back to top
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group