944,147 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Unsolved
  • Views: 2183
  • Python RSS
Nov 6th, 2005
0

File Interactions

Expand Post »
Ok I was wondering if anyone could help me with how to make a python program interact with files. Copying, pasting, moving, things like that, opening. If it cant really be discussed quicky are there any good tutorials? Mainly a organinzing python program.(looks for a certain file extention, then moves it to a desegnated folder)

Advice and help grately apprecated :cheesy:
Similar Threads
Reputation Points: 16
Solved Threads: 1
Junior Poster in Training
danizzil14 is offline Offline
68 posts
since Jul 2005
Nov 7th, 2005
0

Re: File Interactions

The module shutil has copy(from, to) and move(from, to) for your file operations.
Moderator
Reputation Points: 1333
Solved Threads: 1404
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
Nov 8th, 2005
0

Re: File Interactions

Uh..... *drools*

Sorry but i am a noob with this and the only things I've made was a Hello World Program and a specilzied calcultor that does caluclations for the popular internet game Runescape.
Reputation Points: 16
Solved Threads: 1
Junior Poster in Training
danizzil14 is offline Offline
68 posts
since Jul 2005
Nov 9th, 2005
-1

Re: File Interactions

Here is a code snippet of a typical file copy ...
[php]# copy a file to another folder or to another filename
# copy2() retains original date/time, copy() does not

import shutil

# make sure folder and file exists
sourcefile = "D:/Python24/Atest/Audi.jpg"

# destination-folder has to exist
destinationfile = "C:/Temp/Audi.jpg"

try:
shutil.copy2(sourcefile, destinationfile)
except IOError:
print "File or folder does not exist!"
else:
print "File successfully copied!"
[/php]
Moderator
Reputation Points: 1333
Solved Threads: 1404
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: IP adresses
Next Thread in Python Forum Timeline: ssh changes the way python script behaves





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC