GreenTriangle
GreenTriangle

Reputation: 2460

Fastest way to get the size-in-bytes of a folder?

I'm writing a program that measures the sizes of various folders, which can each contain up to 10,000 files. I'm curious about what the best, fastest way to obtain the sizes of these folders would be.

Currently, since I'm just targeting Windows to start with, I'm using the built-in WIN32OLE library's Scripting.FileSystemObject.getFolder.size method. Because the folders are on magnetic disks, I'm using separate threads to check each folder size simultaneously. Is there a smarter way to do it?

Upvotes: 0

Views: 158

Answers (1)

Noman Ur Rehman
Noman Ur Rehman

Reputation: 6957

Here is the code to get the folder size directly. I am assuming the size is in bytes so you can make the calculations regarding KB, MB, and so on

require 'win32ole'
fso = WIN32OLE.new('Scripting.FileSystemObject')
folder = fso.GetFolder('<path-to-folder>')
# gives folder name
folder.name
# gives folder size in bytes
folder.size
# gives folder path
folder.path

Upvotes: 1

Related Questions