LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to get folder size in bytes

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

0 Kudos
Message 1 of 37
(4,865 Views)

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.

0 Kudos
Message 2 of 37
(4,859 Views)

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.

0 Kudos
Message 3 of 37
(4,846 Views)

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

0 Kudos
Message 4 of 37
(4,830 Views)

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. 

0 Kudos
Message 5 of 37
(4,814 Views)

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.Smiley Wink

 

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.

 

 

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 6 of 37
(4,804 Views)

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

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
Message 7 of 37
(4,787 Views)

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?

0 Kudos
Message 8 of 37
(4,689 Views)

Yes. Rewrite the operating system.

0 Kudos
Message 9 of 37
(4,679 Views)

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,

steve.bm
AE | NI
0 Kudos
Message 10 of 37
(4,653 Views)