DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Python (http://www.daniweb.com/forums/forum114.html)
-   -   File Interactions (http://www.daniweb.com/forums/thread34924.html)

danizzil14 Nov 6th, 2005 6:49 pm
File Interactions
 
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:

vegaseat Nov 7th, 2005 12:33 pm
Re: File Interactions
 
The module shutil has copy(from, to) and move(from, to) for your file operations.

danizzil14 Nov 8th, 2005 10:55 pm
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.

vegaseat Nov 9th, 2005 1:15 am
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]


All times are GMT -4. The time now is 6:52 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC