Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [solved] List available drives
Forum Updated to NodeBB v4.3 + New Features

[solved] List available drives

Scheduled Pinned Locked Moved General and Desktop
7 Posts 5 Posters 13.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    ThaRez
    wrote on 10 Oct 2011, 10:45 last edited by
    #1

    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.

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on 10 Oct 2011, 10:49 last edited by
      #2

      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. "/").

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      3
      • T Offline
        T Offline
        ThaRez
        wrote on 10 Oct 2011, 11:03 last edited by
        #3

        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

        1 Reply Last reply
        0
        • F Offline
          F Offline
          fluca1978
          wrote on 10 Oct 2011, 11:48 last edited by
          #4

          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?

          1 Reply Last reply
          0
          • T Offline
            T Offline
            ThaRez
            wrote on 10 Oct 2011, 12:13 last edited by
            #5

            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.)

            1 Reply Last reply
            0
            • L Offline
              L Offline
              lgeyer
              wrote on 10 Oct 2011, 12:27 last edited by
              #6

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

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andre
                wrote on 10 Oct 2011, 14:37 last edited by
                #7

                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.

                1 Reply Last reply
                0

                1/7

                10 Oct 2011, 10:45

                • Login

                • Login or register to search.
                1 out of 7
                • First post
                  1/7
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved