How to handle file names with &
Posted: 16 Sep 2020 21:12
I have a font I want to install called Spirit & Ghost.ttf
The following code processes a list of font files in a folder.
Of course, this fails when it hits the spirit & ghost.ttf file...
How do I handle file names with & in them?
The following code processes a list of font files in a folder.
Code: Select all
SET SRC=%CD:~0,2%
set SrcPath=%SRC%\PostInstall\%USERNAME%
:FONTS
IF EXIST "%SrcPath%\Fonts\" (
Echo Installing Custom Fonts
Echo %time% Installing Custom Fonts >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
FOR %%a in ("%SrcPath%\Fonts\*.?tf") do call :Installfont "%%~nxa"
Echo %time% Fonts will not be available until the system has been restarted >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
)
Goto SYMLNK
:Installfont
Set font=%~1
IF EXIST "%LOCALAPPDATA%\Microsoft\Windows\Fonts\%font%" echo Font %font% already installed. >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
IF EXIST "%WINDIR%\Fonts\%font%" echo Font %font% already installed. >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
IF NOT EXIST "%LOCALAPPDATA%\Microsoft\Windows\Fonts\%font%" IF NOT EXIST "%WINDIR%\Fonts\%font%" (
Set fext=%font:~-3%
IF /i "%fext%"=="ttf" Set ftype=Truetype
IF /i "%fext%"=="otf" Set ftype=Opentype
Echo Installing %font% to "%LOCALAPPDATA%\Microsoft\Windows\Fonts" >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
Echo Processing font %font% Extension: %fext% Type: "(%ftype%)" >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
copy "%SrcPath%\Fonts\%font%" "%LOCALAPPDATA%\Microsoft\Windows\Fonts\%font%" /y >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
REG ADD "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Fonts" /v "%font% (%ftype%)" /d "%LOCALAPPDATA%\Microsoft\Windows\Fonts\%font%" /t REG_SZ /f >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
)
exit /b
:SYMLNK
Echo Finished
Code: Select all
'GHOST.ttf' is not recognized as an internal or external command,
operable program or batch file.