0

By using the code below, I am getting the directory from the source to the destination. However, the time of the destination directory and the source is changed.

import os,time,os.path,shutil
shutil.copytree(sourceFolderPath, destinationFolderPath)

I would like to copy the source directory with their time stamp. Any ideas?

  • 1) This should work. ["Permissions and times of directories are copied with copystat()"](https://docs.python.org/3/library/shutil.html#shutil.copytree) 2) What do you mean by "the source is changed"? –  Apr 03 '18 at 11:42
  • Possible duplicate of [Keeping file attributes on a copy](https://stackoverflow.com/questions/17685217/keeping-file-attributes-on-a-copy) – SiHa Apr 03 '18 at 11:59

1 Answers1

0

First warning on the docs:

Even the higher-level file copying functions (shutil.copy(), shutil.copy2()) cannot copy all file metadata.

On POSIX platforms, this means that file owner and group are lost as well as ACLs. On Mac OS, the resource fork and other metadata are not used. This means that resources will be lost and file type and creator codes will not be correct. On Windows, file owners, ACLs and alternate data streams are not copied.

shutil.copytree uses shutil.copy2()by default:

Permissions and times of directories are copied with copystat(), individual files are copied using shutil.copy2()

Juan Diego Godoy Robles
  • 14,447
  • 2
  • 38
  • 52
  • shutil.copytree copy all, but with new time stamp of directory. But I want source directory time stamp in destination. – Bilal Ali Apr 04 '18 at 07:31