Deleting SymLinks in VB Script

By | April 28, 2011

I recently had to write a script to create symlinks using mklink

Mklink (available since vista) can create unix style symbolic links for folders or files and is particularly useful when we have folders that need to span multiple volumes.
We can create a directory junction by using the syntax :   mklink /j c:\foo c:\bar
browsing c:\foo will show you the contents of c:\bar. Pretty basic.
Deleting a symlink folder (c:\foo) via windows explorer wont delete the actual folder (c:\bar)- only the junction gets deleted. 
However, in vbscript, one gotcha is that when using FileSystemObject methods to manipulate symlinks, the DeleteFolder method will actually delete the contents of the linked folder as well as the junction itself.
This is actually a good thing, as its doing a proper job of deleting the folder, but in this particular case I only wanted to delete the junction not the actual contents. 
In the absence of a proper deletion method for junctions, for me simply calling cmd /c rmdir to remove the junction worked fine as a workaround.

One thought on “Deleting SymLinks in VB Script

Leave a Reply

Your email address will not be published. Required fields are marked *