LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
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: Hagerstown, MD
Distribution: Ubuntu Natty Narwahl
Posts: 258

Rep: Reputation: 31
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: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
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: Hagerstown, MD
Distribution: Ubuntu Natty Narwahl
Posts: 258

Original Poster
Rep: Reputation: 31
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: ubuntu
Posts: 2,530

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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


All times are GMT -5. The time now is 06:03 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration