Size of a Folder
-
Well, I've been trying to get the Size of a Folder with .NET without using Recursion. There dosn't seem to be any property for it and all my searches have given me only ways of getting them using Recursion, which I want to avoid at all costs. Any Advice, Guys ? Simply Yuvi Don't Argue with a Fool : People looking will not know the difference
-
Well, I've been trying to get the Size of a Folder with .NET without using Recursion. There dosn't seem to be any property for it and all my searches have given me only ways of getting them using Recursion, which I want to avoid at all costs. Any Advice, Guys ? Simply Yuvi Don't Argue with a Fool : People looking will not know the difference
The directory/folder structure itself is recursive and as far as I know there is no such information stored in any folder. Technically it could be done but if a file changes one should update this information of all the parent folders and that could make it quite expensive. You could a tree structure containing this size information yourself and have it kept up to date by means of a service. Then you only need to ask that service for the size and you would have the answer immediately. But this is far more complex than the recursive algorithm. A unwanted side effect is that such service would take up CPU time and probably would decrease the performance of your disks. Do you have any requirement that ask for instantanious information? If you just want to avoid recursion you could make an iterative directory walking algorithm but that would imply you should keep track on a stack where you have been. It might be a bit faster but it is harder to code. regards, rob tillaart
-
The directory/folder structure itself is recursive and as far as I know there is no such information stored in any folder. Technically it could be done but if a file changes one should update this information of all the parent folders and that could make it quite expensive. You could a tree structure containing this size information yourself and have it kept up to date by means of a service. Then you only need to ask that service for the size and you would have the answer immediately. But this is far more complex than the recursive algorithm. A unwanted side effect is that such service would take up CPU time and probably would decrease the performance of your disks. Do you have any requirement that ask for instantanious information? If you just want to avoid recursion you could make an iterative directory walking algorithm but that would imply you should keep track on a stack where you have been. It might be a bit faster but it is harder to code. regards, rob tillaart
Thanks Rob. But, Yes, My App does require Instantanious Information. It is something like (Treesize), but also adds that it can actually operate on the files and folders. And, Since it uses a Chart and by it's Very Nature, changes the information about directories often, it does need instantinous Information... And, I suppose I'd be doing some benchmarks about the time required to get the size of them by Recursion and iteration, but I think that It'd take a lot of time, especially for rather big Folders like the Program Files folder.... Simply Yuvi Don't Argue with a Fool : People looking will not know the difference
-
Thanks Rob. But, Yes, My App does require Instantanious Information. It is something like (Treesize), but also adds that it can actually operate on the files and folders. And, Since it uses a Chart and by it's Very Nature, changes the information about directories often, it does need instantinous Information... And, I suppose I'd be doing some benchmarks about the time required to get the size of them by Recursion and iteration, but I think that It'd take a lot of time, especially for rather big Folders like the Program Files folder.... Simply Yuvi Don't Argue with a Fool : People looking will not know the difference
Well, I did run some tests, and it showed that it needs 1 minute 20 seconds to find the size of my primary partition, which is 13 gb full.... And, if i need to get the size of the Program Files Folder inside it, all the Files and Folders Sizes would be queried again! Sure, I could construct a Tree with the Folders and their Sizes, but i suppose there should be a better way.... Simply Yuvi Don't Argue with a Fool : People looking will not know the difference
-
Well, I did run some tests, and it showed that it needs 1 minute 20 seconds to find the size of my primary partition, which is 13 gb full.... And, if i need to get the size of the Program Files Folder inside it, all the Files and Folders Sizes would be queried again! Sure, I could construct a Tree with the Folders and their Sizes, but i suppose there should be a better way.... Simply Yuvi Don't Argue with a Fool : People looking will not know the difference
Hi Yuvi, Two ideas: 1) Monitor 'hot' folders with an other frequency than 'cold' folders. The folder program files is big but does hardly change where the temp folder may be far more active. 2) Use WMI. You can get all kind of events from the OS. Maybe you can subscribe to file (create append delete) events. Then you know where the changes are. I have no experience with it but check http://www.codeproject.com/csharp/WMIproviderGuide.asp[^] for a good backgrounder. regards, rob
-
Hi Yuvi, Two ideas: 1) Monitor 'hot' folders with an other frequency than 'cold' folders. The folder program files is big but does hardly change where the temp folder may be far more active. 2) Use WMI. You can get all kind of events from the OS. Maybe you can subscribe to file (create append delete) events. Then you know where the changes are. I have no experience with it but check http://www.codeproject.com/csharp/WMIproviderGuide.asp[^] for a good backgrounder. regards, rob
Thanks for the Ideas, Rob. Will Sure check WMI out.... Simply Yuvi Don't Argue with a Fool : People looking will not know the difference