创建长文件时,Python IOError异常 [英] Python IOError exception when creating a long file

查看:151
本文介绍了创建长文件时,Python IOError异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当尝试使用"open(fname,'w +')"打开新文件时,出现如下所示的IOError.完整的错误消息如下.

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

该文件不存在,但是我使用"os.access(dir_name,os.W_OK)"和"os.path.exists(dir_name)"验证了该文件的父目录确实存在.

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.

我想知道文件名对于Windows是否太长,或者我做错了什么.任何提示将不胜感激.非常感谢.

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.

错误消息:

IOError:[错误2]没有这样的文件或目录:'C:\ Documents and 设置\管理员\ op_models \ Corp_Network_Nov12 \ abcde_corporate_nov_12.project \ abcde_corporate_nov_12-ctr.rptd.dir \ ctr \ Non 的营业时间 Weeknights \ hourly_data_for_2_weeks \ 1294897740 \ json.data \ Link \ 0 \ Link 利用率\ analyzer393146160-data0.js'

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'

推荐答案

在Windows API中,最大路径长度限制为260个字符.

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

http://msdn.microsoft. com/en-us/library/aa365247%28v = vs.85%29.aspx

更新:在路径前面加上"\\?\".

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

这篇关于创建长文件时,Python IOError异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆