This is one of those “this should only take me 20 minutes to bang out the solution” problems which has kept me occupied, off and on, for the better part of a weekend.
I have a slew of fonts we have licensed for various purposes over the years. Lots of those “1,000+ fonts” DVDs you could buy. I want to rename obscure files such as “garla_n.ttf” into something like “Garland City Regular.ttf” so they at least make sense to someone browsing the directory.
I could use a font manager package, but this needs to work on multiple machines, and I have yet to find a font manager application that will happily batch rename thousands of files.
I banged out a little PowerShell script to do it for me. Get the font info from the ttf/otf, determine a “sane” filename, and rename the file.
Unfortunately “GlyphTypeface” puts a lock on the file, and refuses to let go, and there is no way to destruct the object.
The line:
$fontobject = (New-Object -TypeName Windows.Media.GlyphTypeface -ArgumentList $fontfile.fullname)
Puts a lock on the font file, with no way to release it. There is no Dispose or destructor or Release.
Neither “$fontobject = $null” nor “Clear-Variable fontobject” work. The file lock stays stubbornly fixed until I exit PowerShell. And force invoking the garbage collector fails to yield any different result.