AutoHotkey Community

It is currently May 26th, 2012, 10:51 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: October 29th, 2009, 1:39 pm 
Offline

Joined: May 1st, 2008, 2:18 am
Posts: 21
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 October 29th, 2009, 1:48 pm, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 29th, 2009, 1:42 pm 
Offline

Joined: May 17th, 2007, 12:07 pm
Posts: 1004
Location: Germany - Deutschland
What do you mean by free files?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 29th, 2009, 1:44 pm 
Offline

Joined: May 1st, 2008, 2:18 am
Posts: 21
aaffe wrote:
What do you mean by free files?


files (not directories) that are in the root of the source


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 29th, 2009, 1:47 pm 
Offline

Joined: May 17th, 2007, 12:07 pm
Posts: 1004
Location: Germany - Deutschland
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?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 29th, 2009, 1:49 pm 
Offline

Joined: May 1st, 2008, 2:18 am
Posts: 21
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 29th, 2009, 2:03 pm 
Offline

Joined: November 14th, 2007, 2:47 pm
Posts: 335
Location: London, England
See this: http://www.autohotkey.com/forum/viewtop ... highlight=

Enguneer(sp) helped me out with it.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 29th, 2009, 2:26 pm 
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%".

:?:


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 29th, 2009, 2:31 pm 
Offline

Joined: May 1st, 2008, 2:18 am
Posts: 21
Yes for a directory copy, i know...

but don't works for copy a volume :(


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 29th, 2009, 2:59 pm 
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!

:?: :?:


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: hyper_, JSLover, Leef_me, Maestr0, Miguel, XstatyK and 56 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group