Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / September 2004

Tip: Looking for answers? Try searching our database.

An open source drive space viewer

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Simon Harvey - 26 Aug 2004 14:04 GMT
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
Sayed Hashimi - 09 Sep 2004 21:01 GMT
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

> Hi all,
>
[quoted text clipped - 20 lines]
>
> Simon
Burkhard Perkens-Golomb - 20 Sep 2004 08:54 GMT
> Hi all,

[...]

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

JDiskReport. Google for it.

            Burkhard

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.