473,545 Members | 2,041 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Folder size in VB.NET?

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
3 7872

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
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*********@SP AMhotmail.com> wrote in message
news:u1******** ********@TK2MSF TNGP14.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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
2450
by: Chris | last post by:
Hi, Not sure if this is the right forum, but hopefully someone can help me. I am creating something for our intranet and i want to list the files and folders of a directory, i found some code to do this. The only problem is that it lists the asp file used to for example if i go to: "http://myserver/listing.asp" In the file listing will...
8
4140
by: Ty Moffett | last post by:
What is the best way to find the size of a folder (actually it's contents) on a disk?
2
5030
by: John Regan | last post by:
Hello All I am trying to find the owner of a file or folder on our network (Windows 2000 Server) using VB.Net and/or API. so I can search for Folders that don't follow our company's specified folder structure and naming conventions and then send a Net send message to those users telling them to rectify. The information I want to get is when...
12
4099
by: grouped2000 | last post by:
g'day group, I need some code that will give me the total size of a folder. In the MSDN I've found some code, but I cannot figure out how to use this code at all ... I am quite new to .NET, I have been using VB6 always. Can anyone point me in the right direction? How will the following code give me the total size of al files in
6
3587
by: Caleb Hattingh | last post by:
Hi everyone Unless you have a nice tool handy, calculating many folder sizes for clearing disk space can be a click-fest nightmare. Looking around, I found Baobab (gui tool); the "du" linux/unix command-line tool; the extremely impressive tkdu: http://unpythonic.net/jeff/tkdu/ ; a python script I didn't really understand at...
9
1729
by: Eugene Anthony | last post by:
How do I calculate the size of a folder? Also how do I count the number of images stored in a folder? Eugene Anthony *** Sent via Developersdex http://www.developersdex.com ***
4
7418
by: shuisheng | last post by:
Dear All, I'd like to build a structure similar to the folder tree which 1. Has a root. 2. Nodes can be folder or files. 3. Folder can contain folders and files. 4. Name of folders and files under a folder can not be same. Anybody can give me some hint?
5
2836
by: bharathreddy | last post by:
How to find the size of a folder using C# code? step1: Here take the folder which u want to find the size, then pass that folder to the recursive function name FolderSize!. DirectoryInfo dirInfo = new DirectoryInfo(strPath) ; decimal dSize = 0; //If the folder exists then only its size will be calculated if not its size will...
0
7473
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7661
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7815
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7433
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5976
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5340
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4949
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1891
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1020
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.