Folder weight tool in ASP.NET
Tag it:
Delicious
blogmarks
Stumble
Furl it!
Digg
YahooMyWeb
Technorati
?

ASP.NET Visual Basic application - Disk weight directory report

Index all the files on your hard drive(s) and store them in a SQL server 2005 database

This application lists all your local drives and allows you to scan all your files. As the files are scanned their paths, names and sizes are stored in a database for future retrieval and statistical analysis. The analysis portion of the program will let you see how much space a certain folder takes up on your drive. In addition to being able to search your entire file system, you can also view a graph, that is dynamically generated from the data that was previously acquired from your file system. Sounds like fun! Lets get started...

The first undertaking is to procure the necessary software. Since this program will run in a browser, we will be using visual web developer express. The database software is SQL server express with Management studio express that will help us visually design and debug the data that we will be storing. Both these programs are free. If you own Visual studio you can use that in place of the express versions as it is more feature rich. The free versions provided by Microsoft are ample to create and debug this application.

Create a database called FileSystemDB. Now create a table called fileSystemTable. This table will hold references to all the files on all our drives within the file system. Note that you can also create separate tables for each drive in question depending on the size of your drives. The advantage to having just one table is that it is easy to manage as all the data is located centrally. The disadvantage is speed, especially if you have millions of files.

Here is the SQL code you can use to create the fields.      

Now in Visual Web Developer create a new Dataset, with the default name Dataset1.xsd
Dataset that maps to the fileSystemTable Create a new dataset based on the file system table
You can start designing the interface for the Default.aspx page. Here is what I came up with. Main interface for the application. Runs completely in a web browser.
Interface for the application drive mapping tool

We are importing two classes from System.IO Directory and FileInfo. These classes will enable us to traverse a directory recursively and determine its contents. As you might have gathered from the Dataset, we will also be storing pertinant information about the files.

This subroutine gets all the physical hard drives that you have in your system including the drive names.

This function accepts the currently selected drive. A table adapter is used to clear all the data in the table if the clear all data checkbox on the Default.aspx page is checked.

The subroutine findDirectory(drive) does all the real work along with the subroutine readFilesInDirectory(ByVal .directoryName as String)

One thing to note is that we are not interested in "System Volume Information" directories. Basically we are traversing all the directories. For each directory we call the readFilesIndirectory subroutine By passing it the foundDirectory

This function also contains a reference to the Dataset that we created. The fileSystemTableAdapter is used to insert the file and directory information into the database. We will later use this information to make file searching extremely efficient and responsive.


ASP.NET does not have a native msgbox method. This function is a simple javaScript hack to create a message box. It takes a string as an argument and shows a messagebox with an ok button.


This is the click event for the View Graph button. I am using a properietary flash file to display the graph. Since the code is copyrighted, I unfortunately cannot discuss it. The basic concept is to generate an XML file that is populated at runtime based on the values that you pass to it.
So if you wanted to filter down a particular directory, and see how much space each one of the subdirectories was taking up, you could view the same graphically. It is a really nice way of figuring out what is taking up way too much room on your drives.

The other parts of the program are quite intuitive. I have made an interface to search all the files. To do that I created a text box with a submit button. On the click event of the submit button, a bound gridview control is populated with the results from a simple SQL query.

You can also make the query even more complicating taking the drive information into account eg. c:\windows\......

You can also use SQL to aggregate the fileSize field and group by directory to see how much each directory "weighs"
This information can then be used to populate an XML file based on some graphing interface to visualize your data weight.

Comments
Search
Only registered users can write comments!
wallace530   |Registered |2009-05-19 02:10:17
great post sir..
thanks for sharing. really helped a
lot here.
-------------------------------------------- ---------
ugg boots | ugg
wow gold  - wow gold   |123.145.184.xxx |2009-03-29 23:50:36
Buy wow power leveling and wow power leveling
Last Updated ( Friday, 30 May 2008 )