Where's the problem really? This path exists, but the program fails .
I want to know the cause of this problem?
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.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.