{"id":136,"date":"2009-11-04T21:59:20","date_gmt":"2009-11-04T23:59:20","guid":{"rendered":"http:\/\/www.ragestorm.net\/blogs\/?p=136"},"modified":"2009-11-04T22:03:17","modified_gmt":"2009-11-05T00:03:17","slug":"sad-but-true-really-long-paths","status":"publish","type":"post","link":"https:\/\/www.ragestorm.net\/blogs\/?p=136","title":{"rendered":"Sad But True, Really Long Paths"},"content":{"rendered":"<p>It&#8217;s really an end case, some might claim. Though I find it irritating and I wanted to share it with you guys.<br \/>\nNothing serious, I bet you know it. Well let&#8217;s get to the point then.<br \/>\nMAX_PATH_LEN or however it is exactly defined is 260. 260 bytes long to hold a path and everybody uses that. The thing is that under NTFS you can create really long paths (~32k), when each element (directory name or file name) has to be up to 250+something bytes, so you can chain a few easily as sub-directory and pass the 260 bytes limit.<\/p>\n<p>I created a very long pathname using Python for ease:<\/p>\n<pre lang=\"python\">\r\nimport win32file\r\nwin32file.CreateDirectory(u\"\\\\\\\\?\\\\c:\\\\01\" + \"2\"*250, None)\r\nwin32file.CreateDirectoryW(u\"\\\\\\\\?\\\\c:\\\\01\" + \"2\"*250 + \"\\\\\" + \"3\"*250, None)<\/pre>\n<p>Then if you try to open it with explorer.exe you can enter only the first directory. Of course, you cannot browse the sub-directory, not even right click on it (you get the menu as if you right clicked on the background of the window) or delete it.. Explorer really acts weird with those directories.<br \/>\nLuckily RD \/s <strike>always works<\/strike>, also fails in some cases. I was also trying to create many sub-directories and at some point it didn&#8217;t let me access to the lower sub-directory.<\/p>\n<p>Now I ask myself, usually you ask the path length by passing a NULL instead of a buffer to the API, and this way you get the size, then you allocate that size and ask the data itself by a second call. Almost all Windows API work this way. So why support only 260 bytes full path name? Maybe it&#8217;s not practical to have that long file names? Even if it doesn&#8217;t, you are supposed to malloc already for the second call anyway&#8230; so it turns out people are just lazy and supply a buffer of 260 bytes and that&#8217;s it for first call and go.<\/p>\n<p>One note though:<br \/>\nwhen I say 260 bytes, in reality it&#8217;s 260*2 bytes, cause NTFS stores the names in Unicode.<\/p>\n<p>Waiting for someone to tell me I am wrong about the whole issue.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>It&#8217;s really an end case, some might claim. Though I find it irritating and I wanted to share it with you guys. Nothing serious, I bet you know it. Well let&#8217;s get to the point then. MAX_PATH_LEN or however it is exactly defined is 260. 260 bytes long to hold a path and everybody uses [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","jetpack_publicize_message":""},"categories":[7],"tags":[],"jetpack_featured_media_url":"","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pbWKd-2c","_links":{"self":[{"href":"https:\/\/www.ragestorm.net\/blogs\/index.php?rest_route=\/wp\/v2\/posts\/136"}],"collection":[{"href":"https:\/\/www.ragestorm.net\/blogs\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ragestorm.net\/blogs\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ragestorm.net\/blogs\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ragestorm.net\/blogs\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=136"}],"version-history":[{"count":4,"href":"https:\/\/www.ragestorm.net\/blogs\/index.php?rest_route=\/wp\/v2\/posts\/136\/revisions"}],"predecessor-version":[{"id":140,"href":"https:\/\/www.ragestorm.net\/blogs\/index.php?rest_route=\/wp\/v2\/posts\/136\/revisions\/140"}],"wp:attachment":[{"href":"https:\/\/www.ragestorm.net\/blogs\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=136"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ragestorm.net\/blogs\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=136"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ragestorm.net\/blogs\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=136"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}