Module shutil
[hide private]
[frames] | no frames]

Module shutil

Utility functions for copying files and directory trees.

XXX The functions here don't copy the resource fork or other metadata on Mac.

Classes [hide private]
Error
Functions [hide private]
 
copyfileobj(fsrc, fdst, length=16384)
copy data from file-like object fsrc to file-like object fdst
 
_samefile(src, dst)
 
copyfile(src, dst)
Copy data from src to dst
 
copymode(src, dst)
Copy mode bits from src to dst
 
copystat(src, dst)
Copy all stat info (mode bits, atime and mtime) from src to dst
 
copy(src, dst)
Copy data and mode bits ("cp src dst").
 
copy2(src, dst)
Copy data and all stat info ("cp -p src dst").
 
copytree(src, dst, symlinks=False)
Recursively copy a directory tree using copy2().
 
rmtree(path, ignore_errors=False, onerror=None)
Recursively delete a directory tree.
 
move(src, dst)
Recursively move a file or directory to another location.
 
destinsrc(src, dst)

Imports: os, sys, stat, abspath


Function Details [hide private]

copy(src, dst)

 

Copy data and mode bits ("cp src dst").

The destination may be a directory.

copy2(src, dst)

 

Copy data and all stat info ("cp -p src dst").

The destination may be a directory.

copytree(src, dst, symlinks=False)

 

Recursively copy a directory tree using copy2().

The destination directory must not already exist. If exception(s) occur, an Error is raised with a list of reasons.

If the optional symlinks flag is true, symbolic links in the source tree result in symbolic links in the destination tree; if it is false, the contents of the files pointed to by symbolic links are copied.

XXX Consider this example code rather than the ultimate tool.

rmtree(path, ignore_errors=False, onerror=None)

 

Recursively delete a directory tree.

If ignore_errors is set, errors are ignored; otherwise, if onerror is set, it is called to handle the error with arguments (func, path, exc_info) where func is os.listdir, os.remove, or os.rmdir; path is the argument to that function that caused it to fail; and exc_info is a tuple returned by sys.exc_info(). If ignore_errors is false and onerror is None, an exception is raised.

move(src, dst)

 

Recursively move a file or directory to another location.

If the destination is on our current filesystem, then simply use rename. Otherwise, copy src to the dst and then remove src. A lot more could be done here... A look at a mv.c shows a lot of the issues this implementation glosses over.