(Richard Bos) writes:
> "" <> wrote:
>> Is there a c library which does shutil.copy2() in python? Basically
>> copy a file from 1 directory to another?
>>
>> import shutil
>> import os
>>
>> shutil.copy2(r"C:\test\test",r"C:\test1\test")
>
> I cannot fathom the need for a specific function to copy from one
> directory to another, given both complete file names. Surely if you have
> filename1 and filename2, that should allow you to do a copy from the one
> to the other regardless of whether either of them is in any directory or
> whether the system has directories at all?
> In any case, given two file names, the procedure in C is simple.
> fopen(filename1, "rb"), fopen(filename2, "wb"), fread() from file 1 and
> fwrite() to file 2 until you run out of data, fclose() both files.
> That's it. No need to fret about directories.
If you need your program to be as portable as possible, that's the way
to do it. But very often there can be requirements other than
portability. If I had a need to copy a file in a C program intended
to run under a Unix-like system, I'd invoke the "cp" command; this is
likely (but not certain) to be faster than a pure C solution, and it
gives me more options regarding *how* to copy the file (most of which
are outside the scope of C). Under Windows (implied by the file names
used by the OP), I suppose I'd use "copy" for the same reasons.
I'm not very familiar with Python, but I presume that 'shutil.copy2'
is an abstraction that invokes "cp", or "copy", or whatever. With
some effort, you can build the same kind of abstraction in C -- and
I'm sure it's already been done.
--
Keith Thompson (The_Other_Keith)
kst- <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"