函数getDrivetyPew总是返回drive_no_root_dir

发布于 2025-01-26 06:15:55 字数 818 浏览 1 评论 0原文

如标题所说,标准Windows 返回所有通过路径的值1(驱动器_no_root_dir)。

文档说

根路径无效;例如,没有安装的音量 指定的路径。

尽管我很确定所提供的路径(例如“ c:\\ temp”,“ c:\\ temp”)是有效的,并且固定驱动器(硬盘)。

我想念什么吗?什么可能导致这个?任何帮助都将不胜感激 - 我对Winapi并不熟悉。

bool FileAttributesRetriever::IsExternalPath(const std::filesystem::path& path)
{
    uint32_t driveType = GetDriveTypeW(path.wstring().c_str()); // Always 1 / DRIVE_NO_ROOT_DIR

    switch (driveType)
    {
        case DRIVE_REMOTE:      // Network storage.
        case DRIVE_REMOVABLE:   // External drive.
        {
            return true;
        }
        default:
        {
            return false;
        }
    }
}

As title says, standard Windows GetDriveTypeW returns value 1 (DRIVE_NO_ROOT_DIR) for all passed paths.

Documentation says

The root path is invalid; for example, there is no volume mounted at
the specified path.

Although I'm pretty sure the supplied paths (e.g. "C:\\temp", "c:\\temp") is valid and is fixed drive (hard disk).

Am I missing something? What could possibly cause this? Any help would be appreciated - I'm not very familiar with WinAPI.

bool FileAttributesRetriever::IsExternalPath(const std::filesystem::path& path)
{
    uint32_t driveType = GetDriveTypeW(path.wstring().c_str()); // Always 1 / DRIVE_NO_ROOT_DIR

    switch (driveType)
    {
        case DRIVE_REMOTE:      // Network storage.
        case DRIVE_REMOVABLE:   // External drive.
        {
            return true;
        }
        default:
        {
            return false;
        }
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

2025-02-02 06:15:55

文档还表明,该论点必须是:

驱动器的根目录。
需要一个后斜拉...

也就是说,如果要检查c:drive或c:\ temp \,则应使用c:\调用它。想要检查以c:\ temp安装的驱动器。

The documentation also says that the argument must be:

The root directory for the drive.
A trailing backslash is required...

That is you should call it with C:\ if you want to check the C: drive, or C:\temp\ if you want to check the drive mounted at C:\temp.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文