|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Folder size in VB.NET?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. TyBreaker wrote:
> I have a vbscript which returns the folder size of any folder instantly I don't think Windows does store this info anywhere. For example, in> 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? 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 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.) Show quoteHide quote "TyBreaker" <tybreakerNO@SPAMhotmail.com> wrote in message news:u1L5O%23kUGHA.2444@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. Stephany Young wrote:
> If you ever used the FSO Folder.Size property in VBScript to get the size of Apologies, I re-ran my vbscript just now and it is slow too. Suffering > 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. 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.
Derived TextBox
adding items to a listbox that are null problem Financial.Rate Cannot calculate rate using the arguments provided which is better Problem with - Edit Item of Collections.Generic.List(Of SearchAreaListItem) Shell to DOS Abstract/Base Class Best Practices - Help How to read S.M.A.R.T. attributes in vb ? Instance of derived class does not show public methods or properties that are not in the inherited c Help VS 2005 Dead in Water for VB project |
|||||||||||||||||||||||