Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
santito95
Posts: 134
Registered: ‎02-24-2013
My Device: BlackBerry Z10 LE
Accepted Solution

How can I get a Directory Size using QFileInfo

Hi guys!

 

I'm trying to retrieve the size from a Folder or Directory using QFileInfo but still I can't get it successfully.

 

Someone can help me with any sample?

 

Thanks!

Please use plain text.
Developer
BBSJdev
Posts: 6,116
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30

Re: How can I get a Directory Size using QFileInfo

By size do you mean the total number of bytes of all the files within the directory?

You would need to iterate through the files and add the filesizes.


If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Please use plain text.
Developer
santito95
Posts: 134
Registered: ‎02-24-2013
My Device: BlackBerry Z10 LE

Re: How can I get a Directory Size using QFileInfo

Sure, I need know all bytes content in the directory, can you give me some examples about how can I iterate all files?
Please use plain text.
Developer
BBSJdev
Posts: 6,116
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30

Re: How can I get a Directory Size using QFileInfo

[ Edited ]

Here's an example off the web (not my code)...

 

quint64 dir_size(const QString & str)
{
    quint64 sizex = 0;
    QFileInfo str_info(str);
    if (str_info.isDir())
    {
        QDir dir(str);
        QFileInfoList list = dir.entryInfoList(QDir::Files | QDir::Dirs |  QDir::Hidden | QDir::NoSymLinks | QDir::NoDotAndDotDot);
        for (int i = 0; i < list.size(); ++i)
        {
            QFileInfo fileInfo = list.at(i);
            if(fileInfo.isDir())
            {
                    sizex += dir_size(fileInfo.absoluteFilePath());
            }
            else 
                sizex += fileInfo.size();

        }
    }
    return sizex;
} 

 Obviously you will need to adapt it to your needs (i.e do you want recursion, count hidden, etc).

 

[Edit] Here's the reference for that code http://stackoverflow.com/questions/7096637/how-can-i-get-the-file-size-in-directory-traversal

 


If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Please use plain text.
Developer
santito95
Posts: 134
Registered: ‎02-24-2013
My Device: BlackBerry Z10 LE

Re: How can I get a Directory Size using QFileInfo

[ Edited ]

Thanks BBSJDev

It's working fine but now I've a new issue, it only can show the size of files inside the device Storage, and I need show it also from the sd card

I'm using the following dir: "shared/videos" to show size from videos folder

How can I solve it?

Thanks

Please use plain text.
Developer
santito95
Posts: 134
Registered: ‎02-24-2013
My Device: BlackBerry Z10 LE

Re: How can I get a Directory Size using QFileInfo

I solved it!

using the following Directory:

"../../removable/sdcard/videos"

Thanks!!
Please use plain text.