我这里有一段代码,它从配置文件中复制目录列表等。它运行并复制目录等,但每次运行时仍然出错,任何人都可以帮助我理解为什么会弹出错误或者有什么方法可以抑制它
错误如下:
Traceback (most recent call last):
File "copydir.py", line 22, in <module>
shutil.copytree(sourcefile, destfile)
File "/usr/local/lib/python2.7/shutil.py", line 174, in copytree
os.makedirs(dst)
File "/usr/local/lib/python2.7/os.py", line 157, in makedirs
mkdir(name, mode)
OSError: [Errno 17] File exists: '/export/home/craigdba/My_backups/2012-10-24/'
该代码是
#!/usr/local/bin/python
import shutil
import datetime
import os
today=datetime.date.today()
todaystr=today.isoformat()
confdir=os.getenv("my_config")
dropbox=os.getenv("dropbox")
conffile = ('services.conf')
conffilename=os.path.join(confdir, conffile)
sourcedir=(r'/export/home/craigdba/')
destdir=os.path.join(dropbox, "My_backups"+"/"+todaystr+"/")
#os.makedirs(destdir)
for file_name in open(conffilename):
sourcefile=os.path.join(sourcedir, file_name.strip())
destfile=os.path.join(destdir, file_name.strip())
shutil.copytree(sourcefile, destfile)
提前致谢