I can't help with code, but possibly an alternative suggestion.
I use a number of different image editing programs such as PaintShop Pro and Photoshop Elements. Those programs include a huge number of scripts, bitmaps, sample images, etc. I have 60GB SSD's for my C:\ drive and those clutter up the drive, so I use junctions to move all those to a different physical drive. I normally use junctions for folders, not individual files.
Whenever I create a junction, I rename the original folder by adding a minus, e.g., MSO Cache => -MSO Cache. In the parent folder I add a file called JUNCTION LIST.TXT That contains entries in the format:
C:\MSO Cache was replaced with a junction to S:\<whatever>\MSO Cache
MKLINK <the specific code that was used to create the junction>
I then use that code to actually create the junction.
In the junction target I also put the same file JUNCTION LIST.TXT
If you want to, you can put the contents of all the JUNCTION LIST.TXT files into a single file so you'll have a record in one place.