08-24-2011 12:59 PM
Hi all,
Is there a easy way to get folder size in bytes? I don't want to check each file in it and then add them up.
Thanks for any help.
Anne
08-24-2011 01:14 PM
You can't get that directly. You have to iterate through all subdirectories. At least on Windows. Don't know if Linux or Macs have that capability in the OS. On Windows you can also use System Exec to call Disk Usage.
08-24-2011 02:06 PM
Why don't you want to check each file? It's very easy to use Recursive File List, then in a for loop use File/Directory Info to get an array of sizes. Add Array Elements will then give you a total size of the directory.
08-24-2011 06:38 PM
Because there may be thousands files in the folder and it takes quite a while to get size of each file and then add them up.
I think there should be a more efficient way.
Thanks,
Anne
08-25-2011 08:10 AM
If you go to the properties of a folder in Windows to see the size, it will have to go through and add up all the files inside recursively, this is just how it works. Sure it would be nice if there was a better way, but as far as I know, there isn't.
08-25-2011 08:46 AM
Years ago, I found my home PC was lacking disk space and could not exaplain where all of the space went.
At the same time I was teaching myslef how to use the Picture control and Windows did not allow you to check the size of a folder and it sub-folders. So I used that situation to learn about the picture control and LV at the same time.
It worked and ran but very slowly.
Soon after Greg McKaskle was putting together the first version of "The Good The Bad and The Ugly" and was looking for fodder to beat up. I offered and he accepted. When the time came for the presentation, my code was chosen as "The bad" since I had not learned how to do a cluster sort at that time so I wrote my own version of a bubble sort (the VI presents a Pie Chart of disk usage and clcik on the sectors of the Pie Chart allowed you to drill down so I hd to sort by sizes).
So why am I telling you this long boring story?
That code is attached for you to look at laugh and tell me how dumb I was.
Feel free to beat me up. It can't be any worse than the abuse I got from Greg (I felt like I was being raped).
Have fun!
Ben
Code is probably 6 or thereabouts. "Disk_Utility" is top level. Remember this is an example of how NOT to code.
08-25-2011 09:18 AM
Ben,
this algorithm is somehow familiar to me.......wait, you posted it on yourself in the Rube Goldberg Thread (post Nr. 3) 😉
For those interested: Ben also posted an improved version of the algorithm serving the same purpose, but far better in regard to performance.....
Norbert
11-04-2011 07:04 AM
I was wondering if I could revisit this topic.
I am also trying to get the size of a folder/directory. It will have millions of files in it. So recursively going through all the files will be WAY too slow. I need a quick way to do it. And I am guessing DotNET is the way to go. Any ideas?
11-04-2011 07:37 AM
Yes. Rewrite the operating system.
11-07-2011 01:40 PM
Hi josborne02,
I think that the process for updating the size of a folder/directory is native to the operating system, so I don’t know if there is another way to do this without using the OS resources that, as you said, takes time.
Using .Net, any script or basically any software will do the same, ask the OS and the OS will use the routine it has built in.
Regards,