By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,417 Members | 1,178 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,417 IT Pros & Developers. It's quick & easy.

Folder size in VB.NET?

P: n/a
I have a vbscript which returns the folder size of any folder instantly
by referring to Folder.Size. I don't need any iteration or recursion
through the subfolders, adding together individual file sizes etc.

But I can't find anything comparable in VB.NET or am I missing
something? All the examples I have found online are iterative/recursive
solutions but these take a long time to complete if there are lots of
files/folders in a hierarchy. Windows obviously stores this data
somewhere handy for vbscript so surely there is a way to access this in
VB.NET too?
--
______ ___ __
/_ __/_ __/ _ )_______ ___ _/ /_____ ____
/ / / // / _ / __/ -_) _ `/ '_/ -_) __/
/_/ \_, /____/_/ \__/\_,_/_/\_\\__/_/
/___/

There are 10 types of people in this world; those who understand the
binary numbering system and those who don't.

There's no place like 127.0.0.1.

ASCII a silly question, get a silly ANSI.
Mar 28 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a

TyBreaker wrote:
I have a vbscript which returns the folder size of any folder instantly
by referring to Folder.Size. I don't need any iteration or recursion
through the subfolders, adding together individual file sizes etc.

But I can't find anything comparable in VB.NET or am I missing
something? All the examples I have found online are iterative/recursive
solutions but these take a long time to complete if there are lots of
files/folders in a hierarchy. Windows obviously stores this data
somewhere handy for vbscript so surely there is a way to access this in
VB.NET too?


I don't think Windows does store this info anywhere. For example, in
Windows Explorer, if you get the properties of a folder with many
subfolders, you can _see_ the size being recursively calculated. If it
were stored anywhere, surely Windows Explorer would be a prime
candidate for having access to that information.

When you invoke Folder.Size in VBScript you are using a method in
scrrun.dll, which (I suspect) runs the same recursive process you see
in the .NET sample for Directory. It's just that because scrrun exposes
it as a single method, you don't see the code. Just code up the
standard example, hide it away in a utility class, and you will forget
it is any more than a simple method call :)

It might be interesting to see if you can demonstrate a performance
difference between scrrun.dll's implementation, and a .NET
implementation.

--
Larry Lard
Replies to group please

Mar 28 '06 #2

P: n/a
What makes you think that 'Windows obviously stores this data somewhere
handy for vbscript'?

If you ever used the FSO Folder.Size property in VBScript to get the size of
a folder that contains a large number of files you would know that the
response is by no means instantaneous. This implies that the property
actually calculated the value on the fly.

Now the question becomes, what do you interpret Folder.Size to mean? Do you
interpret it as the total number of bytes taken from the actual size of all
the files and subfolders in the folder or do you interpret as the number of
bytes representing the number of sectors taken up by all the files and
subfolders in the folder?

I note that you state that you don't need to 'recurse' thae subfolders but
that is what the FSO Folder.Size property does.

Given that methods and properties of the FSO were so damn slow it was
probably prudent to include an optimized property to give an approximate
value. (I call it approxomate because I never really figured out just what
it was telling me.)

Using the framework Directory and File classes to 'walk' the contents of a
directory is very fast and you are able to tailor it to give you the exact
information you want. (And you don't have to 'recurse' the sub-directories
if you don't want to.)

"TyBreaker" <ty*********@SPAMhotmail.com> wrote in message
news:u1****************@TK2MSFTNGP14.phx.gbl...
I have a vbscript which returns the folder size of any folder instantly by
referring to Folder.Size. I don't need any iteration or recursion through
the subfolders, adding together individual file sizes etc.

But I can't find anything comparable in VB.NET or am I missing something?
All the examples I have found online are iterative/recursive solutions but
these take a long time to complete if there are lots of files/folders in a
hierarchy. Windows obviously stores this data somewhere handy for
vbscript so surely there is a way to access this in VB.NET too?
--
______ ___ __
/_ __/_ __/ _ )_______ ___ _/ /_____ ____
/ / / // / _ / __/ -_) _ `/ '_/ -_) __/
/_/ \_, /____/_/ \__/\_,_/_/\_\\__/_/
/___/

There are 10 types of people in this world; those who understand the
binary numbering system and those who don't.

There's no place like 127.0.0.1.

ASCII a silly question, get a silly ANSI.

Mar 28 '06 #3

P: n/a
Stephany Young wrote:
If you ever used the FSO Folder.Size property in VBScript to get the size of
a folder that contains a large number of files you would know that the
response is by no means instantaneous. This implies that the property
actually calculated the value on the fly.


Apologies, I re-ran my vbscript just now and it is slow too. Suffering
from selective memory disfunction I think. It does appear to be faster
on subsequent runs for some reason but yes, I admit defeat and will
crawl back into my cave :)

--
______ ___ __
/_ __/_ __/ _ )_______ ___ _/ /_____ ____
/ / / // / _ / __/ -_) _ `/ '_/ -_) __/
/_/ \_, /____/_/ \__/\_,_/_/\_\\__/_/
/___/

There are 10 types of people in this world; those who understand the
binary numbering system and those who don't.

There's no place like 127.0.0.1.

ASCII a silly question, get a silly ANSI.
Mar 28 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.