The shutil module offers a number of high-level operations on files and collections of files. In particular, functions are provided which support file copying and removal.
Caveat: On MacOS, the resource fork and other metadata are not used. For file copies, this means that resources will be lost and file type and creator codes will not be correct.
src, dst) |
fsrc, fdst[, length]) |
src, dst) |
src, dst) |
src, dst) |
src, dst) |
src, dst[, symlinks]) |
The source code for this should be considered an example rather than a tool. Changed in version 2.3: Error is raised if any exceptions occur during copying, rather than printing a message.
path[, ignore_errors[, onerror]]) |
If onerror is provided, it must be a callable that accepts three parameters: function, path, and excinfo. The first parameter, function, is the function which raised the exception; it will be os.listdir(), os.remove() or os.rmdir(). The second parameter, path, will be the path name passed to function. The third parameter, excinfo, will be the exception information return by sys.exc_info(). Exceptions raised by onerror will not be caught.
src, dst) |
If the destination is on our current filesystem, then simply use rename. Otherwise, copy src to the dst and then remove src.
New in version 2.3.
New in version 2.3.