[Tutor] File Copying on Win98
Timothy M. Brauch
tbrauch@mindless.com
Tue, 06 Mar 2001 22:54:54 -0500
Is there a way to copy a file from one place to another in Win 98 with
Python 2.0. The following does *not* work.
import os
contents_0=os.listdir('../CIM2kCD/')
try:
os.mkdir('C:/Program Files/CIM2k/')
except: pass
for item in contents_0:
file=open('../CIM2kCD/'+item,'rb').read()
new=open('C:/Program Files/CIM2kCD/'+item,'w')
new.write('C:/Program Files/CIM2k/'+item)
This produces the following error:
Traceback (innermost last)
File "d:\cim2kcd\list.py", line 11, in ?
new=open('C:/Program Files/CIM2kCD/'+item,'w')
IOError: [Errno 2] No such file or directory:
'C:/Program Files/CIM2kCD/CIM2k.htm'
I understand why it gives me that error, I am trying to open a file that
doesn't exist. But, how else can I copy a file.
All I am trying to do is copy the files in one directory into another
directory. I know there has to be a way to do this, but I cannot for
the life of me figure out how. Also, the files have all kinds of
extensions, like .jpg, .html, .gif, .exe, and others.
- Tim