[Thunar-dev] show total directory sizes?
Jean-François Wauthy
pollux at xfce.org
Thu Mar 23 12:57:11 CET 2006
Le jeudi 23 mars 2006 à 12:09 +0100, Benedikt Meurer a écrit :
> It should be a simple job, which uses one or more threads to determine
> the size of a directory using opendir(), readdir(), closedir() and lstat().
You can start with the xfburn code (taken from gnomebaker in fact). I'm
sure you'll find ways to improve it.
guint64
xfburn_calc_dirsize (const gchar * dirname)
{
/* copied from GnomeBaker */
guint64 size = 0;
GDir *dir = g_dir_open (dirname, 0, NULL);
if (dir != NULL) {
const gchar *name = g_dir_read_name (dir);
while (name != NULL) {
/* build up the full path to the name */
gchar *fullname = g_build_filename (dirname, name, NULL);
struct stat s;
if (stat (fullname, &s) == 0) {
/* see if the name is actually a directory or a regular file */
if (s.st_mode & S_IFDIR)
size += (guint64) s.st_size + xfburn_calc_dirsize (fullname);
else if (s.st_mode & S_IFREG)
size += (guint64) s.st_size;
}
g_free (fullname);
name = g_dir_read_name (dir);
}
g_dir_close (dir);
}
return size;
}
cheers
--
Jean-François Wauthy <pollux at xfce.org>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 191 bytes
Desc: Ceci est une partie de message num?riquement sign?e
URL: <http://mail.xfce.org/pipermail/thunar-dev/attachments/20060323/31dc635b/attachment.pgp>
More information about the Thunar-dev
mailing list