Powershell的字体名称 [英] Name of font by powershell
本文介绍了Powershell的字体名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试编写一个Poweshell脚本,该脚本安装给定目录中的所有字体(格式为.ttf
和.otf
).但是我想忽略已经安装的字体.为此,我需要获取字体的名称(不是文件名).
I'm trying to write a Poweshell script that installs all fonts (in formats .ttf
and .otf
) from a given directory. However I want to ignore fonts that are already installed. For that purpose I need to get the names (not the filenames) of the fonts.
我该怎么办?
推荐答案
来自@LotPings的评论
EDITED from comments from @LotPings
您可以使用.NET.在下面的示例中,您将浏览给定路径中的文件列表,然后使用PrivateFontCollection类检索字体名称.
You can use .NET for that. In the following example you go through the list of files in a given path, then use the class PrivateFontCollection to retrieve the font names.
Add-Type -AssemblyName System.Drawing
$path = "<path to the fonts>\*.ttf"
$ttfFiles = Get-ChildItem $path
$fontCollection = new-object System.Drawing.Text.PrivateFontCollection
$ttfFiles | ForEach-Object {
$fontCollection.AddFontFile($_.fullname)
$fontCollection.Families[-1].Name
}
这篇关于Powershell的字体名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文