Aeron B

Aeron B

  • NA
  • 1
  • 0

Efficiently obtain recursive folder information

May 18 2010 5:23 PM

I am trying to create a tool that recursively queries a given folder for all file/folder information contained within. Specifically, I want to make sure that I capture total number of files/folders and total size of files for each directory.  At first glance it looks like you can do this easily with .Net by simply recursively totaling the size of each folder.  The problem with this approach is that the same information is being queried many times and the duration of the program exponentially increases as more subfolders are queried.  

For example consider the following folders: c:\temp, c:\temp\one, c:\temp\two.  Ideally, instead of recursively querying for all files in each of the three folders, we would only query the two subfolders and then add those together for the top level folder.

In my attached sample, I am creating a dataset that contains  file information and is very quick because there are no redundant queries to the file system.  However, I'm not quite sure the best way to recursively sum the totalsize, totalfiles and totalfolder fields.

I created a primary key and a foreign key as well as a relation to preserve the folder structure, but I have no idea how to walk back up the tree from the lowest folders to properly total each folder.

Perhaps there is an easier way to accomplish what I am trying to do?


Attachment: finfo.zip