Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Determing folder size using c#

Posted on 2007-12-03
11
Medium Priority
?
3,784 Views
Last Modified: 2010-04-21
How can i determine size of a folder in c# once it's been selected by the folderbrowserdialog?

thanks

0
Comment
Question by:DFCRJ
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
11 Comments
 
LVL 21

Expert Comment

by:surajguptha
ID: 20396889
0
 
LVL 21

Expert Comment

by:surajguptha
ID: 20396915
or more simply like this
long total = 0;
foreach(System.IO.FileInfo file in dirInfo.GetFiles())
total += file.Length;
0
 
LVL 14

Accepted Solution

by:
Daniel Junges earned 1200 total points
ID: 20397060

System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo("C:\\tmp");
long size = getDirSize(dir);

public long getDirSize(System.IO.DirectoryInfo dir)
        {
            long size = 0;
            System.IO.DirectoryInfo[] dirs = dir.GetDirectories();
            System.IO.FileInfo[] files = dir.GetFiles();

            foreach (System.IO.FileInfo fi in files)
                size += fi.Length;

            foreach (System.IO.DirectoryInfo di in dirs)
                size += getDirSize(di);
            return size;
        }

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:DFCRJ
ID: 20397376
what would be the best way to display it in the app? tried using a label but returns a conversion error.
I
0
 
LVL 21

Expert Comment

by:surajguptha
ID: 20397514
What code did u use to get the conversion error?
0
 

Author Comment

by:DFCRJ
ID: 20397519
Sorry -

System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo("C:\\tmp");
long size = getDirSize(dir);

public long getDirSize(System.IO.DirectoryInfo dir)
        {
            long size = 0;
            System.IO.DirectoryInfo[] dirs = dir.GetDirectories();
            System.IO.FileInfo[] files = dir.GetFiles();

            foreach (System.IO.FileInfo fi in files)
                size += fi.Length;

            foreach (System.IO.DirectoryInfo di in dirs)
                size += getDirSize(di);
            return size;
        }
0
 
LVL 21

Expert Comment

by:surajguptha
ID: 20397532
where here are u assigning the long value to a label?
0
 

Author Comment

by:DFCRJ
ID: 20397541
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo("C:\\tmp");
long size = getDirSize(dir);
lblsize = size;

amongst other places as well. I'm learning.
0
 
LVL 21

Assisted Solution

by:surajguptha
surajguptha earned 800 total points
ID: 20397550
lblsize.Text = size.ToString()
0
 

Author Comment

by:DFCRJ
ID: 20397571
Oh YEA!!!
0
 

Author Closing Comment

by:DFCRJ
ID: 31412376
Thanks to all who hung in there with a beginner
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question