473,405 Members | 2,167 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

[Errno 18] Invalid cross-device link using os.rename

oldName=/backup/backups/data/WWW_httpd.conf_backups/20050204.httpd.conf

newName=/backup_old/data/WWW_httpd.conf_backups/20050204.httpd.conf

os.rename(oldName,newName) gives:

OSError: [Errno 18] Invalid cross-device link

mv from the shell works fine.

This is Python 2.2.3 from RedHat 9.0.

Any suggestions (other than os.system('mv %s %s')?)

Jul 18 '05 #1
3 16514
Scott Whitney wrote:
os.rename(oldName,newName) gives:

OSError: [Errno 18] Invalid cross-device link

mv from the shell works fine.

This is Python 2.2.3 from RedHat 9.0.

Any suggestions (other than os.system('mv %s %s')?)


catch exception and copy if error == errno.EXDEV.

(this is what "mv" does, of course)

or use shutil.move:
import shutil
help(shutil.move)

Help on function move in module shutil:

move(src, dst)
Recursively move a file or directory to another location.

If the destination is on our current filesystem, then simply use
rename. Otherwise, copy src to the dst and then remove src.
A lot more could be done here... A look at a mv.c shows a lot of
the issues this implementation glosses over.

</F>

Jul 18 '05 #2
mv is a surprisingly complex program, while os.rename is a wrapper
around rename(2) which is probably documented on your system to return
EXDEV under these circumstanes.

os.xxx is generally a fairly thin wrapper around what your OS provides,
and inherits all the "gotchas". For some activities, os.shutil provides
something that is between os.xxx and os.system("xxx") in complexity and
capability.

Jeff

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)

iD8DBQFCEULWJd01MZaTXX0RAuavAKCX1bQui+R5m4q4kIZfxU q3rFoqMgCgpOQq
Z+qkuXf4jsxiPGmJPMm3EOw=
=uBq3
-----END PGP SIGNATURE-----

Jul 18 '05 #3
Thanks, Jeff. I appreciate the input. I just stuck with os.system('mv
%s %s'). Seems to work fine.
On Mon, 14 Feb 2005 18:31:18 -0600, Jeff Epler <je****@unpythonic.net> wrote:
mv is a surprisingly complex program, while os.rename is a wrapper
around rename(2) which is probably documented on your system to return
EXDEV under these circumstanes.

os.xxx is generally a fairly thin wrapper around what your OS provides,
and inherits all the "gotchas". For some activities, os.shutil provides
something that is between os.xxx and os.system("xxx") in complexity and
capability.

Jeff

Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: John J. Lee | last post by:
Today, I wanted to do something like this: def nr_files(dirName) try: return len(os.listdir(dirName)) except OSError, e: if e.errno == errno.ENOENT: return 0 else: raise
13
by: Markus Elfring | last post by:
Do you know a class library that can convert the error/return codes that are listed in the standard header file "errno.h" into a well-known exception hierarchy? Did anybody derive it from...
10
by: jeff regoord | last post by:
A user inputs a float value. The scanf() function gets the value. However, I need to create an error handler with an if else statement saying invalid input if the input is not a number. Does...
3
by: Mac | last post by:
Is it legal to declare errno after you've included errno.h? For example: #include<errno.h> .... int main (void) {
11
by: Vijay Kumar R Zanvar | last post by:
> In <pan.2004.04.22.04.06.05.969827@bar.net> "Mac" <foo@bar.net> writes: > > >Is it legal to declare errno after you've included errno.h? > > > >For example: > > > >#include<errno.h> > > >...
18
by: pete | last post by:
On my system, the following five expressions are true: (HUGE_VAL == HUGE_VAL / 2) (1 / HUGE_VAL == 0) (sqrt(HUGE_VAL) == HUGE_VAL) (sqrt(-1) == HUGE_VAL) (sqrt(-HUGE_VAL) == HUGE_VAL) and
5
by: Urs Beeli | last post by:
I have a question regarding errno. If I understand it correctly, including <errno.h> allows me to check "errno" for error values that some standard library functions may set. This brings up some...
27
by: Deephay | last post by:
Greetings all, I have a program that used the realloc() function to change the allocated size of a buffer, the program works with some arguments, but with some other arguments, it will show me...
4
by: muthu | last post by:
In the following code it gives the error "error: invalid operands to binary &" Why it is happening #include <signal.h> #include <errno.h> #define SIGBAD(signo) ((signo) <= 0 || (signo) >=...
1
by: Rancid Buttchutney | last post by:
I've tried searching the web but I've had little success finding a cross-browser(IE, Firefox and Opera anyway) implementation of a restricted text INPUT that works in realtime before a character...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.