Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
hellofont/rename-font.ps1
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
35 lines (31 sloc)
1.43 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# # 获取当前的Windows身份 | |
# $currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent()) | |
# # 检查是否拥有管理员权限 | |
# if (-not $currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { | |
# # 构建用于启动新实例的参数 | |
# $arguments = "& '" + $myinvocation.mycommand.definition + "'" | |
# Start-Process powershell -Verb runAs -ArgumentList $arguments | |
# # 退出当前实例 | |
# exit | |
# } | |
$scriptPath = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent | |
# 获取所有文件,并移除隐藏属性 | |
Get-ChildItem -Path $scriptPath -Force -Filter "*" -Recurse | ForEach-Object { | |
$_.Attributes = $_.Attributes -band -not [System.IO.FileAttributes]::Hidden | |
} | |
$fontFiles = Get-ChildItem -Path $scriptPath -Filter "*" -Recurse #重新获取文件列表,确保隐藏属性已移除 | |
foreach ($fontFile in $fontFiles) { | |
$originalName = $fontFile.Name | |
$extension = $fontFile.Extension | |
# 读取字体文件本身的名称 | |
$fontName = (New-Object System.Drawing.FontFamily $fontFile.FullName).Name | |
echo $fontName | |
# # 如果文件名不包含扩展名,则添加扩展名 | |
# if ($originalName -notmatch "\.\w+$") { | |
# $newName = "$fontName$extension" | |
# } else { | |
# $newName = $fontName | |
# } | |
# # 重命名文件 | |
# Rename-Item -Path $fontFile.FullName -NewName $newName -Force | |
} |