[solved] List available drives



  • Hi
    How could I list all available hard drives? My intention is to create a system that recognizes a particular removable drive. The idea was to scan all connected drives and have an ID file on the correct target (as the drive letter might change). If there's a better way (which there probably is.. :P) I'd be grateful for suggestions...Thank you!
    Best regards
    Richard

    ps. The code I tried to use was:

    @QString folder = "";

    QDir dir(folder);
    QStringList files = dir.entryList();
    

    @

    (as the root folder was unknow) but this only listed "random" stuff. Probably also worth noting is that I'm on a Window platform and this is my primary target, though I'd be nice to get it to work on other platform as well.



  • You can list drives on Windows only. For other operating systems you just get the root file system:

    bq. "QDir::drives()":http://doc.qt.nokia.com/4.7/qdir.html#drives
    Returns a list of the root directories on this system.
    On Windows this returns a list of QFileInfo objects containing "C:/", "D:/", etc. On other operating systems, it returns a list containing just one root directory (i.e. "/").



  • Thank you! One further question, is it possible to identify a particular removable drive, without adding a "identity file" to it? (a custom file which the software looks for)
    Richard



  • I guess you have to deal with the registry and look for mounted drives (\devices\harddiskN), but I don't know how to recognize them easily. After all, the beauty is to have a removable drive to work as a fixed drive...
    Nevertheless, I don't think placing a file into the removable media could do the trick for you. What happens if a user deletes the file?



  • That's the downside, I know... and the reason why I'd like to find a alternative solution. However in this case it's for such a specific solution that it "can" be assumed that the user does not remove the ID file. Anyway, it's a poor solution in lack of a better one. (it's not actually a removable disk I'm working with, but a device that can act as one, and the purpose is for the software to recognize that the device is connected and move some logg files to it.)



  • You might take a look at "libblkid":http://linux.die.net/man/3/libblkid. I'm quite sure Windows has something comparable.



  • KDE's Solid API (which is implemented on Linux, Windows and Mac) has the concept of a Device UID. That is basically what you seem to be looking for, and it is appearantly feasable to implement that on all the platforms.

    Note that if you want to list the storage media on the system, you can also use Qt Mobility SystemInfo API' s (also works on the desktop!) to list the devices, and get access to the URL's they reside on.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.