Representation of junctions in Windows

1

I'm using a set of junctions to move my user folder tree to another drive, as my OS install is on a rather small SSD. However, the junctions still appear as if they occupy space on the SSD. Can I do something to change this?

Wolfish

Posted 2017-06-30T22:23:35.550

Reputation: 123

Answers

2

I believe you're looking in the wrong direction here. The representation of junctions is already correct (and if you still changed it to achieve the result you want, junctions could no longer work) – but it's probably not the same kind of representation that you're expecting to see.

Junctions themselves occupy very little space, but so do folders (directories) – if you asked the OS for a folder's size, you'd get a few kB; only as much as necessary to store the file list.

Instead, when programs show the "total size" of a folder (be it in Windows Explorer or du -hs or another app), they actually calculate it manually by listing all the files and adding up their sizes. They do this recursively, by descending into anything that looks like a directory.

The key point is that junctions pass both "is this a directory" and "is this a link" checks, and this is the whole point of junctions. Therefore, if you tried to change this at OS level so that junctions no longer looked like directories, then obviously they could not be used anymore for their main purpose.

So in reality your file manager needs to distinguish junctions (or rather, reparse points) from regular folders, and not try to 'descend' into them when calculating the total size. This is the same as with symlinks in Linux.

You might have more luck with Windows' symbolic links (mklink /d, introduced in Windows Vista) – they're similar to junctions, but might be just different enough to make your file manager program recognize them.

user1686

Posted 2017-06-30T22:23:35.550

Reputation: 283 655

This is interesting stuff. Given that I'm using Explorer, would the appearance of the junction to be x GB in size affect how my storage works, rather than how it appears? I'll give the symbolic link a shot later on.

Edit: Also, not only is Total size a number of GB, but so is Size on Disk - is that relevant here? – Wolfish – 2017-07-01T11:42:56.200

Noi, it wouldn't affect anything. Explorer calculates "Size on Disk" in the exact same way – adding up all files' "sizes on disk"; the only difference from "Total Size" is that it accounts for compressed files, cluster sizes, etc. dir in Command Prompt would give a more direct answer. – user1686 – 2017-07-01T16:24:11.033

(At least Explorer finally recognizes junctions when trying to delete them. Back in WinXP, trying to delete a junction via GUI used to make Explorer delete its target's contents too...) – user1686 – 2017-07-02T17:29:01.390