"fixing" physical "free space" on Windows
Tags: windows
Published: 2023-10-30 19:34:02

I don't know if this is just my computer or my hard drive or something stupid, but here I am to write about it:

Notice anything unnatural about large files you have? For example, this (NTFS compressed) video that's 500 MB.
![Victim #1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1cbcmba6og1pqrxfvht1.png)
On the disk, it should physically take up 500 MB, right?
![Free space before deleting it](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ikkkcxyn5cj8a007hi0x.png)
APPARENTLY NOT.
![Free space after deleting it](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nn5rddvlh3shx5ai67zz.png)
(it takes up 600 MB at the start of copying, and then spends the rest of the 400MB while the progress bar loads... !?!?!?!?!?!?!)

Maybe because I have it compressed. That makes no sense, but I wonder what happens if that's turned off.
![Attributes](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fxr45wrodg3qiew17tyc.png)
![Before uncompressing](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2j1v49q2qhvjbv598wwf.png)
![Attributes](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7zzuj8zrl7i6ry3psv9z.png)
![After uncompressing](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/doig8jrgof1ojs7jcvhi.png)
Huh? I gained space?? What if I recompress it?
![After recompressing, showing attributes](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kb1rjq6s4snx5q3suar5.png)
?????
(this apparently doesn't happen on my SSD)

Copying the uncompressed file in a folder that does not have compression turned on makes it not take up more space than it really does. !?!?!?!?!?!?!?!?!?!?!?!

To investigate further, I made a little shell script (with Cygwin) (a little broken, though) that takes files/folders as arguments, and for each individual file, read the total amount of free space of the disk the file is on before and after running Windows' COMPACT command, and if space was taken up after uncompressing it or decompressing it (depending on the attribute it started off with), revert the change.
However, the above example proved this to be made slightly useless because only a select few files actually took more space due to being compressed, which was the motive for making this script.
In most of my use cases involving hundreds of files, it gradually is able to free little amounts of space. I've tested this on other big video files and a few gigabytes were freed up.
![Shell script](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s1j1a29vamngsp4wnf5x.png)
[Download script](https://gist.github.com/donnaken15/3644e2ad328a5c727d689ccb865da963)
(requires Cygwin, should work on a POSIX shell like dash)

[Download Real Time Disk Size Monitor](https://github.com/donnaken15/RTTCBW/raw/master/RTDSM.exe)

Compressing a folder of music:
![example 2 (1/2)](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/finq26x629vxemdxs0ev.png)
![example 2 (2/2)](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ruurlzd68dwuq0dn4xxh.png)

![example 3](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z8l7kdas6gxlpnxqz2j2.png)


I've held off publishing this for about a week now probably because I don't know a conclusion for this article, but I can just say ALL OF THIS MAKES NO SENSE!!!!!!!!