2

Where's the problem really? This path exists, but the program fails .

I want to know the cause of this problem?

enter image description here

    const std::filesystem::directory_options options = (
    std::filesystem::directory_options::follow_directory_symlink |
    std::filesystem::directory_options::skip_permission_denied
    );

try
{
    for (const auto& dirEntry :
        std::filesystem::recursive_directory_iterator("C:\\Users\\myuser",
            std::filesystem::directory_options(options)))
    {

        std::cout << dirEntry.path().generic_string() << std::endl;


    }

}
catch (std::filesystem::filesystem_error & fse)
{
    std::cout << fse.what() << std::endl;
}

C:/Users/myuser/Contacts/{857B728B-5B31-4F94-B832-522DF52E4335}/VertiPaq_68547BCEF3A344CDA3CE/724C7FC1B3284E4BBE1C.3.db/Model.193.cub/Cuentas por Cobrar_f7776207-ea17-4002-8801-3561d1b2d1fc.92.det/Cuentas por Cobrar_f7776207-ea17-4002-8801-3561d1b2d1fc.23.prt recursive_directory_iterator::operator++: The system cannot find the path specified.

1

1 Answer 1

3

The problem is probably that std::filesystem can only be a portable abstraction of the implementations actual file system. According to your path, I assume you are using Microsoft Windows.

So the problem is clear: Your path is to long: Its 260 visible characters plus the invisible end/null/termination character. This is bigger than MAX_PATH, see this documentation.

In the Windows API (with some exceptions discussed in the following paragraphs), the maximum length for a path is MAX_PATH, which is defined as 260 characters.A local path is structured in the following order: drive letter, colon, backslash, name components separated by backslashes, and a terminating null character.

Sign up to request clarification or add additional context in comments.

5 Comments

Thank you, so how do I fix this problem?
Not using so long paths, or requiring Windows 10 Version 1607 or later and using the Windows API directly, with all the needed extra steps for enabling as described in the link I posted, which would be too much for a SO post.
Is there any way that I skip it?
As I said the only options: A) Don't use such long paths B) Don't use windows C) Use at the mentioned Windows 10 version and the linked steps D) Use some other language/runtime/library which uses another API or does the steps of C for you, if there is any
D2) Try the Unicode work arounds in the posted link Please don't forget to accept the answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.