Python IOError exception when creating a long file

AshD picture AshD · Jan 13, 2011 · Viewed 9.9k times · Source

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'

Answer

cgohlke picture cgohlke · Jan 13, 2011

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.