Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding actual size of a folder in Windows

On my home desktop which is a Windows machine I right click on C:\Windows folder under properties and it displays:

enter image description here

If I use the du tool provided by Microsoft sysinternals

du C:\Windows

This produces

Files:        77060
Directories:  21838
Size:         31,070,596,369 bytes
Size on disk: 31,151,837,184 bytes

If I run the same command as administrator

Files:        77894
Directories:  22220
Size:         32,223,507,961 bytes
Size on disk: 32,297,160,704 bytes

With Powershell ISE running as administrator I ran the following powershell snippet from this SO answer

"{0:N2}" -f ((Get-ChildItem -path C:\InsertPathHere -recurse | Measure-Object -property length -sum ).sum /1MB) + " MB"

which output

22,486.11 MB

The C# code in the following SO answer from a command prompt running as Administrator returns:

35,163,662,628 bytes

Although close it still does not display the same as Windows Explorer. None of these methods therefore return the actual size of the directory. So my question is this.

Is there a scripted or coded method that will return the actual folder size of C:\Windows

If there is no way of retrieving the folder size, is there a way I can programatically retrieve the information displayed by Windows Explorer?

like image 682
Bruno Avatar asked Sep 11 '14 00:09

Bruno


People also ask

How do I find the size of a folder in Windows?

Go to Windows Explorer and right-click on the file, folder or drive that you're investigating. From the menu that appears, go to Properties. This will show you the total file/drive size. A folder will show you the size in writing, a drive will show you a pie chart to make it easier to see.

How can I see folder size in details?

This is what you need to do: Right-click on the folder you want to view the size in File Explorer. Select “Properties.” The File Properties dialogue box will appear displaying the folder “Size” and its “Size on disk.” It will also show the file contents of those particular folders.


2 Answers

When it comes to windows they have a strange way of actually storing data, for example while a file maybe 1mb in size, when stored on disc its probably going to be 1.1mb the reason for this being is that includes the directory link to the actual file on disc and that estimated size isn't including the possible additional data windows stores with the associated data.

Now your probably thinking, thats nice and all but how do you explain the massive size change when looking at the file size from admin, well that is a good question because this is another additional header/meta data that is stored in conjunction with the file which is only allowed to be seen by admins.

Coming back to your original question about telling the actual size of the file, well that is quite hard to say for windows due to the amount of additional data it uses in conjunction with the desired file, but for readability purposes or if you are using this for some form of coding, I'd suggest looking for the size on disk with the admin command, not because it seems like the file is at its maximum size (for me it is) but because usually when you are looking to transfer that's probably the most reliable figure you can go with, because once you transfer the file, some additional data will be removed or changed and you already know what the likely swing in file size difference will be.

Also you have to take into account the hard drive format (NTFS, fat32) because of how it segments files because that too can change the file size slightly if the file is huge Ie. 1gb++

Hope that helps mate, because we all know how wonderful windows can be when trying to get information (sigh).

like image 56
Pariah Avatar answered Oct 03 '22 13:10

Pariah


The ambiguities and differences have a lot to do with junctions, soft links, and hard links (similar to symlinks if you come from the *nix world). The biggest issue: Almost no Windows programs handle hard links well--they look like (and indeed are) "normal" files. All files in Windows have 1+ hard links.

You can get an indication of "true" disk storage by using Sysinternals Disk Usage utility

> du64 c:\windows

Yields on my machine:

DU v1.61 - Directory disk usage reporter
Copyright (C) 2005-2016 Mark Russinovich
Sysinternals - www.sysinternals.com

Files:        204992
Directories:  57026
Size:         14,909,427,806 bytes
Size on disk: 15,631,523,840 bytes

Which is a lot smaller than what you would see if you right-click and get the size in the properties dialog. By default du64 doesn't double count files with multiple hard links--it returns true disk space used. And that's also why this command takes a while to process. You can use the -u option to have the disk usage utility naively count the size of all links.

> du64 -u c:\windows

DU v1.61 - Directory disk usage reporter
Copyright (C) 2005-2016 Mark Russinovich
Sysinternals - www.sysinternals.com

Files:        236008
Directories:  57026
Size:         21,334,850,784 bytes
Size on disk: 22,129,897,472 bytes

This is much bigger--but it's double counted files that have multiple links pointing to the same storage space. Hope this helps.

like image 45
Robert Avatar answered Oct 03 '22 13:10

Robert