.NETGURU
An open source drive space viewer
Messages   Related Types
This message was discovered on microsoft.public.dotnet.academic.

Post a new message to this list...

Simon Harvey
Hi all,

I am looking to make an open source Drive space viewer. One that displays
the sizes in a graph and lets you move through the directories via a
treeview at the left.

I have three questions i hope someone could help with:

1. The problem I have is tallying up the directories and sub
directories. This is made even more complicated by the fact that I need to
allow the user to exclude certain sub directories when doing the
calculations. Does anyone know if there is a class in the framework that, at
the very least, can tell me the size of a folder and its contents.

2. Does anyone have any code or suggestions about how I could handle the
problem of excluding various directories. The user needs to click a tick box
in the treeview to have that dir included

3. Does anyone know of an open source application that I could look at for
this purpose

Thank you everyone

Simon

Reply to this message...
 
    
Sayed Hashimi
Simon,

1) .NET Framework has two classes that you can use to obtain the
information specific to files and directories. They are: FileInfo and
DirectoryInfo. Unfortunately, there is not a method on the
DirectoryInfo class to return the size of the Directory. I wrote a
little helper class that has a method on it that will return the size
of the directory in bytes. Here it is:

public class FileSystemHelper
    {
        private FileSystemHelper()
        {
        }
        // returns the size of the given directory in bytes.
        public static long GetDirectorySize(DirectoryInfo di)
        {
            if(di==null)
            {
                throw new ArgumentNullException("di");
            }
            long size = 0;
            FileInfo[] files = di.GetFiles();
            // sum up file size
            if(files!=null && files.Length>0)
            {
                foreach(FileInfo fi in files)
                {
                    size+=fi.Length;
                }
            }
            // sum up dir size
            DirectoryInfo[] dirs = di.GetDirectories();
            if(dirs!=null && dirs.Length>0)
            {
                foreach(DirectoryInfo dii in dirs)
                {
                    // recursive call
                    size+=FileSystemHelper.GetDirectorySize(dii);
                }
            }
            return size;
        }
        
    }

You can get to the contents of the directory by calling GetFiles() and
GetDirectories().

2) GetFiles() and GetDirectories() is overloaded to accept a
searchPattern so you can use that to exclude certain
files/directories.

3) I don't know of any open source tools that do this kind of stuff.

sayed

"Simon Harvey" <Click here to reveal e-mail address> wrote in message news:<Click here to reveal e-mail address>...
[Original message clipped]

Reply to this message...
 
 
System.ArgumentNullException
System.IO.DirectoryInfo
System.IO.FileInfo




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification