({{, (RefLink[CopyDirectory, paclet:ref/CopyDirectory])["(Subscript[dir, 1])","(Subscript[dir, 2])"]
copies the directory (Subscript[dir, 1]) to (Subscript[dir, 2]). }})

OpenersNotesSection(Spacer1)Details

(Subscript[dir, 1]) must already exist; (Subscript[dir, 2]) must not.

(RefLink[CopyDirectory, paclet:ref/CopyDirectory]) copies all the files in (Subscript[dir, 1]) to (Subscript[dir, 2]).

(RefLink[CopyDirectory, paclet:ref/CopyDirectory]) sets the modification dates for (Subscript[dir, 2]) and for all the files in it to be the same as those for (Subscript[dir, 1]).

(RefLink[CopyDirectory, paclet:ref/CopyDirectory]) returns the full name of the directory it copies to, and (RefLink[$Failed, paclet:ref/$Failed]) if it cannot complete the copy.

Directories can be specified either using "path" or (RefLink[File, paclet:ref/File])["path"].

OpenersPrimaryExamplesSection(Spacer1)Examples  (2)

OpenersExampleSection0(Spacer1)Basic Examples  (1)

Copy a directory:

dir=FileNameJoin[{$InstallationDirectory,"SystemFiles","Kernel","TextResources","English"}];

cdir=FileNameJoin[{$TemporaryDirectory,"test123"}];

CopyDirectory[dir,cdir]

List of files in the directory:

FileNames["*",cdir]//Column

Delete the directory:

DeleteDirectory[cdir,DeleteContents-> True]

The directory is no longer there:

FileNames["*",cdir]

OpenersExampleSection1(Spacer1)Scope  (1)

Copy a directory specified as a (RefLink[File, paclet:ref/File]) object::

dir=FileNameJoin[{$InstallationDirectory,"SystemFiles","Kernel","TextResources","English"}];

cdir=FileNameJoin[{$TemporaryDirectory,"test123"}];

CopyDirectory[File[dir],File[cdir]]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[RenameDirectory, paclet:ref/RenameDirectory])  ▪  (RefLink[CreateDirectory, paclet:ref/CreateDirectory])  ▪  (RefLink[DeleteDirectory, paclet:ref/DeleteDirectory])  ▪  (RefLink[CopyFile, paclet:ref/CopyFile])}})}})

({{DocumentationFooterIconsRelatedTutorial.png, ({{Tutorials}, {▪(RefLinkPlain[Manipulating Files and Directories, paclet:tutorial/ManipulatingFilesAndDirectories])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[File Operations, paclet:guide/FileOperations])}, {▪(RefLinkPlain[Directories & Directory Operations, paclet:guide/DirectoriesAndDirectoryOperations])}})}})