python 创建文件失败,创建长文件时出现Python IOError异常

I get an IOError shown below when trying to open a new file using "open (fname, 'w+')". The complete error message is below.

The file does not exist, but I verified using "os.access(dir_name, os.W_OK)" and "os.path.exists (dir_name)" that the parent directory for the file does exist.

I am wondering if the file name is just too long for Windows, or if I am doing something wrong. Any tips would be appreciated. Thank you very much.

Error message:

IOError: [Errno 2] No such file or directory: 'C:\Documents and

Settings\Administrator\op_models\Corp_Network_Nov12\abcde_corporate_nov_12.project\abcde_corporate_nov_12-ctr.rptd.dir\ctr\Non

Business Hours for

Weeknights\hourly_data_for_2_weeks\1294897740\json.data\Link\0\Link

Utilization\analyzer393146160-data0.js'

解决方案

In the Windows API the maximum path length is limited to 260 characters.

Update: prepend "\\?\" to the path.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值