moving a file in a filesystem-independent way?
geoff at gerrietts.net
Fri Jan 31 00:48:50 CET 2003
Quoting Fernando Perez (fperez528 at yahoo.com):
> This problem is nasty because the structure of unix filesystems is
> such that things can change drastically from one machine to
> anonther. It's the first time that I find python being 'dumber'
> than the plain shell commands.
> But I'm sure it's me being dumb, not python :) So I'd appreciate any
> enlightenment on why things are this way, or how I should go about
> the problem.
As recently as 8 years ago, mv was that dumb, too. On some Unix
systems, it still is.
The issue of transparency stands behind your problem. The functions in
os.posix (and consequently available in os) are very close to the
functions provided by the standard C library on your Linux system. The
standard library's rename() function (man 2 rename) returns an error
in the event that the source and destination are not on the same
The convenience function you propose makes sense, but I'm not sure if
replacing rename() is the right solution -- a new method called move
might be preferable, to avoid confusion.
Geoff Gerrietts "I don't think it's immoral to want to
<geoff at gerrietts net> make money." -- Guido van Rossum
More information about the Python-list