LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-25-2005, 11:00 PM   #1
drj000
Member
 
Registered: Sep 2004
Location: Houston, TX
Distribution: Fedora
Posts: 261

Rep: Reputation: 33
Python Question - moving file across filesystems


I just started learning Python, so my question may be fairly obvious, but I haven't been able to find an answer.
I was writing a plugin for madman in Python, but for it to work, I need to be able to move a file across filesystems. os.rename doesn't work across filesytsems (in Linux, at least). Is there another way to do it, aside from creating a new file, copying the contents from the original file to the new one, and then deleting the old file? If I have to do that, I will. It just seems there should be a simpler way.
 
Old 01-26-2005, 06:22 AM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Quote:
Is there another way to do it, aside from creating a new file, copying the contents from the original file to the new one, and then deleting the old file? If I have to do that, I will. It just seems there should be a simpler way.
Most likely there's no other way from within python.
You could run the "mv" program from your python script. This will do a rename if source and destination are on the same filesystem, if not it will revert to copy/delete automatically.
 
Old 01-26-2005, 09:26 AM   #3
drj000
Member
 
Registered: Sep 2004
Location: Houston, TX
Distribution: Fedora
Posts: 261

Original Poster
Rep: Reputation: 33
Oh never mind. I just figured it out. shutil.move() does it. Thanks anyway.
 
Old 01-26-2005, 11:36 AM   #4
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
I learned something about python as well here...
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
python gui file dialog question mulciber Programming 0 07-26-2005 07:37 AM
Moving filesystems, any problems? audibel Linux - Newbie 2 03-19-2005 10:15 AM
python call function in same file(very newbie question) rmanocha Programming 2 11-21-2004 12:04 AM
Question on filesystems and partitions TPupAZ Linux - Software 6 10-02-2003 11:47 PM
Different filesystems question Newbie kato678 Linux - Newbie 4 02-20-2002 02:20 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:33 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration