how to determine if files are on same or different file systems
Kamus of Kadizhar
yan at NsOeSiPnAeMr.com
Sun Dec 7 06:49:47 EST 2003
Peter Otten wrote:
> No need to determine it beforehand, just try (untested):
>
> def movefile(src, dst):
> try:
> os.rename(src, dst)
> except OSError:
> shutil.copy2(src, dst)
> os.remove(src)
>
>
> Of course, if you are using Python 2.3 you should use shutil.move() as
> pointed out by Serge Orlov; the above was mostly posted to illustrate the
> popular concept "It's easier to ask forgiveness than permission", i. e.
> with Python's powerful exception handling mechanism you need not fear the
> failure of a particular code snippet, as long as you provide the
> appropriate error handling.
Peter:
I am copying 600mb - 1.2gb files over slow wireless to an NFS mount -
not exactly the model of reliability. It takes 40 minutes to an hour to
copy one of these. I am paranoid of failures - I don't want to lose movies.
So, I don't want to rely on innate error handling, because the failure
could come from wireless failure, and the copy could fail as well.
That's why I'm looking for a way to tell if a particular partition is
network mounted.
The basic idea is that movies get moved on the same partition, but
copied (and not deleted) when moving between network mounted partitions
and local partitions. Deletes will be subject to manual review until I
get a comfort factor.
>
> Random remarks:
> - You might take a look at os.path.join()
> - Ok, this is paranoia, but I would ensure that ".avi" is only at the end of
> the string
".avi$" ? I still haven't figured out Python's string handling really
well. Or use the length of the string and count backwards? I admit, I
got lazy on this one.
> - Use methods of the str object rather than functions in the string module,
> e. g. "abc".replace("a", "d") rather than string.replace("abc", "a", "d")
OK, I'll try that.
-Kamus
--
What am I on?
I'm on my bike, o__
6 hours a day, busting my ass. ,>/'_
What are you on? --Lance Armstrong (_)\(_)
More information about the Python-list
mailing list