Steven D'Aprano <steve+comp.lang.pyt...@pearwood.info> writes: > On Tue, 03 Apr 2012 15:46:31 -0400, D'Arcy Cain wrote: > >> On 03/28/12 16:12, John Ladasky wrote:
>>> I'm looking for a Python (2.7) equivalent to the Unix "cp" command. >> >>>open("outfile", "w").write(open("infile").read()) > Because your cp doesn't copy the FILE, it copies the file's CONTENTS, > which are not the same thing. > Consider: > * permissions > * access times > * file ownership > * other metadata > * alternate streams and/or resource fork, on platforms that support them > * sparse files > By the time you finish supporting the concept of copying the file itself, > rather than merely its content, you will have something similar to the > shutil.copy command -- only less tested. A minor point, but shutil.copy only "copies" contents and permissions (no access times, etc.) You probably mean shutil.copy2. And sparse files are really hard to reproduce, at least on Unix: on Linux even the system's cp doesn't guarantee sparseness of the copy (the manual mentions a "crude heuristic"). But of course shutil.copy is the best solution to mimic a raw cp. -- Alain. -- http://mail.python.org/mailman/listinfo/python-list