[Qt-interest] Qt show folder size
Andrei Sebastian Cimpean
andreiamenta at gmail.com
Fri Sep 18 15:37:34 CEST 2009
On Friday 18 September 2009 04:15:11 pm Sean Harmer wrote:
> On Friday 18 Sep 2009 13:17:56 Andrei Sebastian Cimpean wrote:
> > On Friday 18 September 2009 02:52:28 pm Sean Harmer wrote:
> > > On Friday 18 Sep 2009 12:09:02 Andrei Sebastian Cimpean wrote:
> > > > This returns a standard size around 4 kb:
> > > > QString::number(fileorfolder.size(),10)
> > > > Does anyone know how to get the sum of all the items inside the
> > > > folder? Thank you
> > >
> > > Yes, iterate through them and sum the sizes. Should be trivial with
> > > QDirIterator and QFileInfo.
> > >
> > > Sean
> > > _______________________________________________
> > > Qt-interest mailing list
> > > Qt-interest at trolltech.com
> > > http://lists.trolltech.com/mailman/listinfo/qt-interest
> >
> > How fast is this way of doing it?
>
> Try it and find out - should only take approx 10 lines of code if that. ;-)
>
> > I mean for a folder with 100k the number
> > of subfolders and files wouldn't it take ages?
>
> Do you really have a dir with 100k items in it? The last time I cloned my
> laptop linux install rsync reported that I only had 1.2 million files for
> the entire image (Gentoo with lots and lots of unpacked source tarballs
> lying around). If you do encounter this type of use case, then you could
> always cache results for sub-dirs and just watch for when individual
> subdirs change with QFileSystemWatcher for e.g.
>
> I know of no other way of finding out the total size of files other than
> querying the size of each and adding them up. This is all that tools like
> du do - plus some additional checking for not counting hardlinked files
> multiple times etc.
>
> Cheers,
>
> Sean
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
Thanks a lot man. You were really helpful. Kudos for that.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090918/6a45161d/attachment.bin
More information about the Qt-interest-old
mailing list