CopyDirectory["dir1","dir2"]
copies the directory dir1 to dir2.
CopyDirectory
CopyDirectory["dir1","dir2"]
copies the directory dir1 to dir2.
Details
- dir1 must already exist; dir2 must not.
- CopyDirectory copies all the files in dir1 to dir2.
- CopyDirectory sets the modification dates for dir2 and for all the files in it to be the same as those for dir1.
- CopyDirectory returns the full name of the directory it copies to, and $Failed if it cannot complete the copy.
- CopyDirectory also works with cloud objects.
- Directories can be specified either using "path" or File["path"].
Examples
open all close allBasic Examples (1)
dir = FileNameJoin[{$InstallationDirectory, "SystemFiles", "Kernel", "TextResources", "English"}];
cdir = FileNameJoin[{$TemporaryDirectory, "test123"}];
CopyDirectory[dir, cdir]List of files in the directory:
FileNames["*", cdir]//ColumnDeleteDirectory[cdir, DeleteContents -> True]The directory is no longer there:
FileNames["*", cdir]Scope (2)
Copy a directory specified as a File object::
dir = FileNameJoin[{$InstallationDirectory, "SystemFiles", "Kernel", "TextResources", "English"}];cdir = FileNameJoin[{$TemporaryDirectory, "test123"}];CopyDirectory[File[dir], File[cdir]]Copy a directory to a cloud object (upload it to the cloud):
dir = FileNameJoin[{$InstallationDirectory, "SystemFiles", "Kernel", "TextResources", "English"}];obj = CopyDirectory[dir, CloudObject[]]Use CloudObjects to list the entries in the cloud directory:
Information[CloudObjects[obj], "DisplayName"]Copy a cloud object directory to a local directory:
dir2 = FileNameJoin[{$TemporaryDirectory, CreateUUID["wl-"]}]CopyDirectory[obj, dir2]List the files copied from the cloud to the local directory:
Map[FileNameTake, FileNames["*", dir2]]DeleteDirectory[dir2, DeleteContents -> True]Copy cloud object to another cloud object:
obj2 = CopyDirectory[obj, CloudObject[]]List of the cloud objects in the copied cloud directory:
Information[CloudObjects[obj2], "Name"]DeleteDirectory[obj, DeleteContents -> True]
DeleteDirectory[obj2, DeleteContents -> True]Tech Notes
Related Guides
History
Introduced in 1991 (2.0) | Updated in 2016 (11.0)
Text
Wolfram Research (1991), CopyDirectory, Wolfram Language function, https://reference.wolfram.com/language/ref/CopyDirectory.html (updated 2016).
CMS
Wolfram Language. 1991. "CopyDirectory." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2016. https://reference.wolfram.com/language/ref/CopyDirectory.html.
APA
Wolfram Language. (1991). CopyDirectory. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/CopyDirectory.html
BibTeX
@misc{reference.wolfram_2026_copydirectory, author="Wolfram Research", title="{CopyDirectory}", year="2016", howpublished="\url{https://reference.wolfram.com/language/ref/CopyDirectory.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_copydirectory, organization={Wolfram Research}, title={CopyDirectory}, year={2016}, url={https://reference.wolfram.com/language/ref/CopyDirectory.html}, note=[Accessed: 12-June-2026]}