Microsoft Windows is not so bad, is it? But in my experience it can be greedy as it comes to disk usage. Not that this is necessarily always Windows to blame, but also third party software or other reasons.
Whatever the reason is, if it happens you have a problem. But don’t panic, luckily there is something you can do about it!
But what situations are we talking about? I can give you some examples:
Windows updates eating disk space (does the folder “SoftwareDistribution” ring a bell?)
Visual Studio 2015 with full mobile development installation taking 40GB for that part only!
Software for navigation equipment that does need temporary space for downloading an update but has no way to choose the folder to download it to (my experience was with Garmin).
Just lots of huge files in “My music” or “My videos”, where basicly of course, there is no one to blame but you.
On a computer with a large amount of memory, having “hybernate” enabled. If you put a computer in “hybernate” all the memory contents is saved to disk, so when you have 16GB of RAM, you will need this amount of free disk space.
You have partitioned your disk to a “Windows” and a “Data” partition (aka a C- and a D-drive), but your underestimated the disk space required for the C-drive.
Your disk is not full but you want to store user data (documents, pictures, music and so on) on a different drive, e.g. so you can easily restore an image of Windows without copying your user data back after the restore.
Ways to free up disk space on drive C
The are more ways to free up disk space. However I want to focus on one solution, here is a (non-complete) list of things you could do:
Compress folders that you do not use frequently. This will save disk space but will cost cpu power when accessing the files in that folder(s).
If you have partitioned your disk, increase the size of the C-drive (and therewith decrease the size of the D-drive).
Using Windows utilities to free up disk space (can help but is not always you can regain enough diskspace with this)
Uninstall programs you do no longer need.
Use junctions. This is the solution I will dive into in this blog post.
Using junctions – prerequisites
There is one important requirement when it comes to junctions: you need to have more than one (fixed) disk or partition in your computer. If it is a second physical disk or a second partition on one disk does not matter. And of course you need to have free disk space on that second disk or partition.
So when you have a notebook with only a small sized SSD, and it is full, junctions can not do much for you.
WARNING!Don’t make junctions pointing to folders on removable drives, like USB pen drives, SD cards and so on for system-critical folders, otherwise applications might stop working or Windows would not even start!
Using junctions – how it works
First of all, what the heck is a junction?
I got to know junctions (also called a soft link) as a shortcut for a folder. This shortcut behaveslike a folder but redirects all applications that access that folder to a different folder. Cool, hey?
Okay, suppose you have Garmin software installed, you have only a few gigabytes free disk space and want to install a Garmin update on your device. Beforestarting to download and install the update, this is what you can do:
Create a cmd script and store it on your computer (call it e.g. create_junctions_garmin.cmd)
Paste this into the empty cmd file. Adjust the bold folder names if needed.
@echo off echo — STEP 1 – CREATE TARGET FOLDER(S) — pause mkdirD:\Junctions mkdirD:\Junctions\ProgramData mkdirD:\Junctions\ProgramData\Garmin echo Please check that the previous step was completed succesfully . . . echo If errors occurred close the command window WITHOUT PRESSING ENTER ! ! ! pause echo — STEP 2 – COPY FOLDER AND ALL SUBFOLDERS AND FILES — pause xcopy “C:\ProgramData\Garmin” “D:\Junctions\ProgramData\Garmin” /E /K /X echo Please check that the previous step was completed succesfully . . . echo If errors occurred close the command window WITHOUT PRESSING ENTER ! ! ! pause echo — STEP 3 – REMOVE SOURCE FOLDER — pause rmdir /s /q “C:\ProgramData\Garmin“ echo Please check that the previous step was completed succesfully . . . echo If errors occurred close the command window WITHOUT PRESSING ENTER ! ! ! pause echo — STEP 4 – CREATE JUNCTION FOR SOURCE FOLDER — pause mklink /j “C:\ProgramData\Garmin” “D:\Junctions\ProgramData\Garmin“ pause
3. Run the cmd file as Administrator and check that it runs without errors. Alternatively you could also move the folder including subfolders and files manually and create a cmd script that only contains STEP 4 – CREATE JUNCTION FOR SOURCE FOLDER
If files are locked, maybe you have to reboot and start Windows in Safe mode, then run the cmd script again.
Moving userdata to a different drive
However Windows offers to some extend the possibility to move these folders, in my experience still downloaded files, pictures or documents sometimes are stored on the C-drive. By creating junctions this is not the case.
I recommend to move this user folders manually and create only the junctions with a cmd script.
Warning / disclaimer: However this works fine for me on Windows 7 and 10 and I do not expect any problems if you follow the procedure, please try this at your own risk.
Note: this works also on non-English versions of Windows as the displayed localized folder names (e.g. in Dutch: “Documenten” for “Documents”) are not the actual folder names. So for the junctions you need to use the English names.
This is what you can do (adjust the bold folder names: replace Hans with your Windows username and replace D:\USERDATA with some other folder if you like)
Create a folder D:\USERDATA\Hans
Create a cmd script and store it on your computer (call it e.g. create_junctions_userdata.cmd)
Paste this into the empty cmd file
Note that you can select the folders of your choice, this list is just an example.
Use Windows Explorer to go to the folder C:\Users\Hans
Select the following folders while pressing the CTRL key: Contacts, Documents, Downloads, Favourites, Music, OneDrive, Pictures, Searches, Videos.
Note that you can select the folders of your choice, but make sure every folder selected is in your cmd script.
Press CTRL+X (Cut)
Navigate to the folder D:\USERDATA\Hans
Press CTRL+V (Paste)
Run the cmd file as Administrator and check that the junctions are created.
For your interest, on the Windows drive the little arrow in the corner of the folder icon reveals that these “folders” are now actually junctions.
Conclusion / Wrap up
With junctions you can replace a Windows folder with a “shortcut” to a different folder.
This can amongst others be handy when you have lack of disk space on the Windows drive.
It is strongly recommended to create only junctions that redirect to folders on fixed drives.
I have explained some examples of how you can use junctions, but you can use junctions for other applications as well. Beware that in some cases files in folders you want to make a junction for can be locked. Stopping the Windows Services or applications accessing those files can help, or starting Windows in Safe Mode (I must admit I did not try this but in theory it should work).
(c) 2016 hansmichiels.com – Do not steal the contents – spread the link instead – thank you.
Business Intelligence and Datawarehouse Consultant using Microsoft Technology