首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > perl python >

咄咄怪事!为什么不能创建与已存在文件同名的目录呢

2013-01-05 
怪事!为什么不能创建与已存在文件同名的目录呢?比如说Windows的D盘下已经有一个文件temp,不带任何后缀,但

怪事!为什么不能创建与已存在文件同名的目录呢?
比如说Windows的D盘下已经有一个文件temp,不带任何后缀,但是没有名为temp的目录。此时如果调用:
os.mkdir("D:\\temp")或者os.makedirs("D:\\temp"),却总是报错 WindowsError: [Error 183] : 'D:\\temp1',查询错误码信息为:ERROR_ALREADY_EXISTS 183 (0xB7) Cannot create a file when that file already exists.
真的搞不懂了~~~求教
[解决办法]

import os

if os.path.isfile("D:\\temp"):
    os.remove("D:\\temp")
    os.mkdir("D:\\temp")

热点排行