Is it possible to find out if a drive path (e.g. P:/temp/foo) is local or remote?
Here ( CMD line to tell if a file/path is local or remote? ) it's shown for a cmd evaluation, but I am looking for a C++/Qt way.
Related to:
Is it possible to find out if a drive path (e.g. P:/temp/foo) is local or remote?
Here ( CMD line to tell if a file/path is local or remote? ) it's shown for a cmd evaluation, but I am looking for a C++/Qt way.
Related to:
There's no way in Qt, at least up to Qt 5.5. QStorageInfo would be the closest fit, but there is no agreement about how such an API should look like (see the gigantic discussion that started in this thread; basically one risks to have Qt reporting misleading information).
So, for now, you're up to using native APIs. The aforementioned GetDriveType would be fine for Windows, but you're pretty much on your own on Linux and Mac.
you could use the GetDriveType function:
https://msdn.microsoft.com/en-us/library/windows/desktop/aa364939(v=vs.85).aspx
I recently filed a feature request about this exact question: https://bugreports.qt.io/browse/QTBUG-83321
A possible workaround emerged there. Using the following enum:
enum DeviceType {
Physical,
Other,
Unknown
};
I could reliably check a mount to be a local device or something else (possibly a net mount) using the following function on Linux, Windows and macOS:
DeviceType deviceType(const QStorageInfo &volume) const
{
#ifdef Q_OS_LINUX
if (QString::fromLatin1(volume.device()).startsWith(QLatin1String("/"))) {
return DeviceType::Physical;
} else {
return DeviceType::Other;
}
#endif
#ifdef Q_OS_WIN
if (QString::fromLatin1(volume.device()).startsWith(QLatin1String("\\\\?\\Volume"))) {
return DeviceType::Physical;
} else {
return DeviceType::Other;
}
#endif
#ifdef Q_OS_MACOS
if (! QString::fromLatin1(volume.device()).startsWith(QLatin1String("//"))) {
return DeviceType::Physical;
} else {
return DeviceType::Other;
}
#endif
return DeviceType::Unknown;
}