Mailing List Archive

Copying Huge Files ? (Newbie!)
Hi,


I want to copy some files across the disks of my server using python
parse a script and then do what I want.

But while reading the manual I cannot find something like os.copyfile
or os.movefile.

Are there some functions except open/read/write that can do the copy
for me ???



Ciao
Matthias Barmeier
Copying Huge Files ? (Newbie!) [ In reply to ]
On Thu, 12 Aug 1999, you wrote:
> Hi,
>
>
> I want to copy some files across the disks of my server using python
> parse a script and then do what I want.
>
> But while reading the manual I cannot find something like os.copyfile
> or os.movefile.
>
> Are there some functions except open/read/write that can do the copy
> for me ???
>
>
>
> Ciao
> Matthias Barmeier


Take a look at the things in shutil (especially shutil.copy and
shutil.copyfile) and os (especially os.rename and os.renames).

--
Fredrik Henbjork

Email: frehe491@student.liu.se
WWW: http://o112.ryd.student.liu.se
Copying Huge Files ? (Newbie!) [ In reply to ]
On Thu, 12 Aug 1999, Fredrik Henbjork wrote:

> On Thu, 12 Aug 1999, you wrote:
> >
> > I want to copy some files across the disks of my server using python
> > parse a script and then do what I want.
> >
> > But while reading the manual I cannot find something like os.copyfile
> > or os.movefile.
> >
> > Are there some functions except open/read/write that can do the copy
> > for me ???

> > Ciao
> > Matthias Barmeier
>
> Take a look at the things in shutil (especially shutil.copy and
> shutil.copyfile) and os (especially os.rename and os.renames).

I'd like to point out that especially if the files are indeed huge, then
the operating system file copy operations may be *much* more efficient
than shutil.copy*, e.g. by using mmap when appropriate.

os.system() can be your friend...

--david
Copying Huge Files ? (Newbie!) [ In reply to ]
Matthias> But while reading the manual I cannot find something like
Matthias> os.copyfile or os.movefile.

Matthias> Are there some functions except open/read/write that can do
Matthias> the copy for me ???

Matthias,

You'll have to open the input and output file, then read and write chunks
yourself, for example (untested!):

def copy(fromfile, tofile, chunksize=8192):
f = open(fromfile, "rb")
t = open(tofile, "wb")
data = f.read(chunksize)
while data:
t.write(data)
data = f.read(chunksize)
f.close()
t.close()

Skip Montanaro | http://www.mojam.com/
skip@mojam.com | http://www.musi-cal.com/~skip/
847-971-7098
Copying Huge Files ? (Newbie!) [ In reply to ]
Matthias Barmeier wrote:
>
>
> I want to copy some files across the disks of my server using python
> parse a script and then do what I want.
>
> But while reading the manual I cannot find something like
> os.copyfile or os.movefile.
>
> Are there some functions except open/read/write that can do the copy
> for me ???

shutil.py in lib/.

- Gordon
Copying Huge Files ? (Newbie!) [ In reply to ]
> while reading the manual I cannot find something like os.copyfile
> or os.movefile.


Look at the shutil (shell utilities) module, it has a copyfile function.
Moving a file (within the same file system) is accomplished by os.rename.
To move a file across filesystems you must use copy, then os.remove the
original.
Copying Huge Files ? (Newbie!) [ In reply to ]
On Thu, 12 Aug 1999 18:14:12 GMT, barmeier@mamba.com (Matthias
Barmeier) wrote:


Thanx a lot for all the answers.
I have used the shutil.py and it works fine. May a bit slow baut for
now its fast enough !

Ciao
Matze