FileCopyDir - I don't get it! Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
User avatar
PuzzledGreatly
Posts: 863
Joined: 29 Sep 2013, 22:18

FileCopyDir - I don't get it!

17 May 2020, 18:44

I'm trying to copy the contents of a single folder from one drive to a thumbdrive (q:\) I thought FileCopyDir would work since help states:
Copies a folder along with all its sub-folders and files (similar to xcopy).
But the following didn't work as expected:

Code: Select all

FileCopyDir, D:\test, Q:\, 1
I end up with four files from D*\test on Q:\ rather than a folder named test on Q:\ with its four files and single subfolder (containing another 33 files).

And then this adds to the confusion:
If the destination directory structure doesn't exist it will be created if possible....

FileCopyDir copies a single folder. To instead copy the contents of a folder (all its files and subfolders), see the examples section of FileCopy.

The last line seems to totally contradict everything before. How to copy a folder and it's subfolders and files from one location to another?
User avatar
Smile_
Posts: 226
Joined: 03 May 2020, 00:51

Re: FileCopyDir - I don't get it!  Topic is solved

17 May 2020, 18:57

Maybe you meant this

Code: Select all

FileCopyDir, D:\test, Q:\test, 1
User avatar
JoeWinograd
Posts: 1507
Joined: 10 Feb 2014, 20:00

Re: FileCopyDir - I don't get it!

17 May 2020, 19:32

The last line seems to totally contradict everything before. How to copy a folder and it's subfolders and files from one location to another?
The seeming contradiction is explained in this thread:
https://www.autohotkey.com/boards/viewtopic.php?f=14&t=69966

Regards, Joe
User avatar
PuzzledGreatly
Posts: 863
Joined: 29 Sep 2013, 22:18

Re: FileCopyDir - I don't get it!

17 May 2020, 19:48

Thanks, that was it. I still find the help file confusing on this.
User avatar
JoeWinograd
Posts: 1507
Joined: 10 Feb 2014, 20:00

Re: FileCopyDir - I don't get it!

17 May 2020, 21:04

Hi PG,
I agree that the doc is confusing on this and could be written better, but I think that gregster did a good job in that post explaining it. Regards, Joe
garry
Posts: 2285
Joined: 22 Dec 2013, 12:50

Re: FileCopyDir - I don't get it!

18 May 2020, 08:11

I tried these examples to copy
1st example with built in robocopy

Code: Select all

#warn
#noenv
setworkingdir,%a_scriptdir%
If !A_IsAdmin                                     ;- copyall needs admin
	Run *RunAs "%A_AhkPath%" "%A_ScriptFullPath%"
Process, Priority, , H
;--- maybe a logfile  exclude logfile if it's in source 
fd1=%a_desktop%\ROBOCOPY_LOG       
ifnotexist,%fd1%
   filecreatedir,%fd1%
logfile ="%fd1%\%a_now%_Robocopy_Log.txt"
excludex=%logfile%                                ;- exclude logfile if it's in source 

DEST=%a_desktop%\TEST ;- << copy here for TEST
preselect=%a_desktop%
FileSelectFolder,src,%preselect%,2,Select folder 
if (src="")
     return
;- parameter XO = copy only changed or new
;runwait,%comspec% /k robocopy %src% %dest% /E /COPYALL   ;- copyall needs admin
runwait,%comspec% /k robocopy %src% %dest% /UNILOG+:%logfile% /E /XO /R:3 /W:15 /UNICODE /ETA /TEE /XD %excludex%
;run,%dest%
ifexist,%logfile%
 run,%logfile%
exitapp
esc::exitapp
;============================================

Code: Select all

#warn
#noenv
setworkingdir,%a_scriptdir%
DEST=%a_desktop%\TEST        ;- << copy here for TEST
ifnotexist,%dest%
  filecreatedir,%dest%
preselect=C:\test
;preselect=%a_desktop%
FileSelectFolder,fd1,%preselect%,2,Select folder 
if (fd1="")
     return
i=0
Loop, Files, %fd1%\*.*, FD  ; Include Files and Directories
{
c:=a_loopfilefullpath
SplitPath,c, name, dir, ext, name_no_ext, drive
aa:=FileExist(c)   ;- D when folder / A when file
  {
  if (AA="D")
    FileCopyDir,%c%,%dest%\%name%  ;- create folder\subfolder and copy files
  if (AA="A")
    FileCopy,%c%,%dest%            ;- copy file without folder
  }
}
run,%dest%
exitapp
esc::exitapp
;==========================================================

Return to “Ask For Help”

Who is online

Users browsing this forum: JackMa, rpgfreak128 and 274 guests