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. how can I have information about a dir
Forum Updated to NodeBB v4.3 + New Features

how can I have information about a dir

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 4 Posters 1.3k Views 2 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    is there a function to know information about a dir like dimension and date of creation?

    Pl45m4P 1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      You can use QFileInfo (yes I know it has "file" in name, but it works for directories, too) to get creation date. I have no idea what you mean by "dimension" - directory size? If so, then you need to manually count all the files or use platform-specific APIs to get the size. QFileInfo will only return you the size of directory descriptor.

      (Z(:^

      ? 1 Reply Last reply
      4
      • ? A Former User

        is there a function to know information about a dir like dimension and date of creation?

        Pl45m4P Offline
        Pl45m4P Offline
        Pl45m4
        wrote on last edited by
        #3

        @vale88

        Have a look at this or this to get dimension (amount of subDirs). You can sort Dirs in a list by modified time with the filter QDir::Time... but dont know how to print out the value from specific QDir.

        Hope it helps :)


        If debugging is the process of removing software bugs, then programming must be the process of putting them in.

        ~E. W. Dijkstra

        1 Reply Last reply
        2
        • sierdzioS sierdzio

          You can use QFileInfo (yes I know it has "file" in name, but it works for directories, too) to get creation date. I have no idea what you mean by "dimension" - directory size? If so, then you need to manually count all the files or use platform-specific APIs to get the size. QFileInfo will only return you the size of directory descriptor.

          ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          @sierdzio I wrote:

            QFileInfo fi(path_definitivo);
          
          
                      double dimensione = fi.size();
                      QString dim_bytes = QString::number(dimensione);
          

          "fi" is a dir, but dimensione is 0, but it'isn't possible because inside dir there is a file that has a size of 1kb

          Pl45m4P sierdzioS 2 Replies Last reply
          0
          • ? A Former User

            @sierdzio I wrote:

              QFileInfo fi(path_definitivo);
            
            
                        double dimensione = fi.size();
                        QString dim_bytes = QString::number(dimensione);
            

            "fi" is a dir, but dimensione is 0, but it'isn't possible because inside dir there is a file that has a size of 1kb

            Pl45m4P Offline
            Pl45m4P Offline
            Pl45m4
            wrote on last edited by
            #5

            @vale88

            QFileInfo works on Dirs too, but not in general.

            Returns the file size in bytes. If the file does not exist or cannot be fetched, 0 is returned.

            It seems XY.size() does not work on directories

            If you need a reliable solution, you have to iterate through all sub-directories and sum all file sizes


            If debugging is the process of removing software bugs, then programming must be the process of putting them in.

            ~E. W. Dijkstra

            1 Reply Last reply
            3
            • JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #6

              No OS (well, Linux or Windows at least) offers a "size" attribute on directories which gives the size of all its contents, or for that matter the number of children, whether you use QFileInfo or not. It would be too slow/hard to maintain updated. If you want to know either of those you have to walk all the children (recursively if you want to know about sub-content) and count for yourself.

              1 Reply Last reply
              3
              • ? A Former User

                @sierdzio I wrote:

                  QFileInfo fi(path_definitivo);
                
                
                            double dimensione = fi.size();
                            QString dim_bytes = QString::number(dimensione);
                

                "fi" is a dir, but dimensione is 0, but it'isn't possible because inside dir there is a file that has a size of 1kb

                sierdzioS Offline
                sierdzioS Offline
                sierdzio
                Moderators
                wrote on last edited by
                #7

                @vale88 said in how can I have information about a dir:

                "fi" is a dir, but dimensione is 0, but it'isn't possible because inside dir there is a file that has a size of 1kb

                As I already wrote:

                you need to manually count all the files or use platform-specific APIs to get the size. QFileInfo will only return you the size of directory descriptor.

                (Z(:^

                1 Reply Last reply
                3

                • Login

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