[filesystem] Windows long paths (and also API differences)

In a simple test program I used create_directories with long path (longer then MAX_PATH being equal to 260 on my machine). ANSI version (for char) threw an exception but before reaching MAX_PATH (somewhere around 255 characters however I did not test exactly). UNICODE version (for wchar_t) created as many directories as it could (as many as would make ANSI version not throw) and skipped rest without throwing anything. This seems bad. Why is it so? And is the MAX_PATH file system limitation on Windows or is it just a limitation for some API functions? Also by the way I wanted to ask why signatures of many functions differ from the documentation. For example no function takes error code parameter and thus always throws on failure (excluding the above example...). In some places I would prefer to have that parameter instead. Also copy_file does not take the third parameter allowing it to do replacing. Why is it so? I am using Boost 1.39 (1.40 does not work for me somehow, when I try to use it it gives compilation errors as I already mentioned in a previous thread) and Visual Studio 2005 on Vista machine. Adam Badura

On Tue, Sep 8, 2009 at 7:01 AM, Adam Badura<abadura@o2.pl> wrote:
In a simple test program I used create_directories with long path (longer then MAX_PATH being equal to 260 on my machine). ANSI version (for char) threw an exception but before reaching MAX_PATH (somewhere around 255 characters however I did not test exactly). UNICODE version (for wchar_t) created as many directories as it could (as many as would make ANSI version not throw) and skipped rest without throwing anything.
Could you post your "simple test program"?
This seems bad. Why is it so? And is the MAX_PATH file system limitation on Windows or is it just a limitation for some API functions?
Windows has various rules, depending on the version, exact syntax used, etc. Thus it would help if you could be much more specific about the problem you are having, version of operating system, etc.
Also by the way I wanted to ask why signatures of many functions differ from the documentation. For example no function takes error code parameter and thus always throws on failure (excluding the above example...). In some places I would prefer to have that parameter instead. Also copy_file does not take the third parameter allowing it to do replacing. Why is it so?
It sounds like you are trying to use the V3 documentation from the sandbox with the current 1.40.0 V2 release. That's a non-starter. --Beman

Could you post your "simple test program"?
The test program is: #include <iostream> #include <boost/exception.hpp> #include <boost/filesystem.hpp> int main() { typedef boost::filesystem::path path_type; const path_type::string_type FOLDER_NAME = "Adam"; try { path_type path( "D:/" ); for ( int i = 0; i < 49; ++i ) path /= FOLDER_NAME; std::cout << path.external_directory_string() << " (" << path.external_directory_string().size() << ")" << std::endl; boost::filesystem::create_directories( path ); } catch ( ... ) { std::cerr << boost::current_exception_diagnostic_information(); } return 0; } However I rechecked it. wchar_t indeed throws. I must have missed it somehow. Sorry. My bad. But I was mistaken by create_directories side effects. It created as much folders as possible and then threw without deleting the folders it really created. In the example above 49 iterations is a limit. For 50 iterations there is a failure of too long path. However for 50 iterations the path reaches length of 252 so I do not understand why this error happens. And still there is a limit with this function.
Windows has various rules, depending on the version, exact syntax used, etc. Thus it would help if you could be much more specific about the problem you are having, version of operating system, etc.
Windows Vista Home Premium SP2. However all this seems to be Windows internal limitations. When I opened the 49th created folder in Windows Explorer and tried to make a new folder there I got a message of too long path. (Also pasting there a folder with 1 character name resulted in this error.) Even more interestingly making a new file there works fine however the file starts with no name (only extension) since the default new file name is too long. However the file accepts name of 7 characters (so with extension it is 11). After all likely everything is fine with Boost.Filesystem. Sorry for trouble.
Also by the way I wanted to ask why signatures of many functions differ from the documentation. For example no function takes error code parameter and thus always throws on failure (excluding the above example...). In some places I would prefer to have that parameter instead. Also copy_file does not take the third parameter allowing it to do replacing. Why is it so?
It sounds like you are trying to use the V3 documentation from the sandbox with the current 1.40.0 V2 release. That's a non-starter.
No. I never do. I used http://www.boost.org/doc/libs/1_40_0/libs/filesystem/doc/reference.html#Oper... And I went there in what I guess is a standard way. Boost Main Page / Documentation / 1.40.0 (Current Release) / Filesystem / Reference / Other operations functions. Adam Badura
participants (2)
-
Adam Badura
-
Beman Dawes