创建包含 unicode 路径的快捷方式

Create shortcut containing unicode path

我试图在 Windows 7 中创建快捷方式,但在我尝试了几次 google 之后,结果发现在 PowerShell 中没有办法。

问:还有其他方法可以批量创建支持unicode路径和文件名的快捷方式吗?

尝试使用符号 link,但当 unicode 路径时它不起作用(returns 文件不存在)。

New-Item -ItemType SymbolicLink -Path "C:\f[o]o♭\pr[o]file♭.txt" -Value "C:\b[a]r♭\pr[o]file♭.txt"

我使用的代码,但在 unicode 路径、文件名时不起作用。

$WshShell = New-Object -ComObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut($lnkpath)
$Shortcut.TargetPath = $tarpath
$Shortcut.Save()

google 搜索之一: Create shortcut with Unicode character


感谢您的及时回复,那我试试看。

$tarpath = "C:\f[o]o♭\pr[o]file♭.txt"
$lnkpath = "C:\b[a]r♭\pr[o]file♭.txt"

$tarpath = $tarpath.Replace('[','`[')
$tarpath = $tarpath.Replace(']','`]')
$lnkpath = $lnkpath.Replace('[','`[')
$lnkpath = $lnkpath.Replace(']','`]'

# echo print $tarpath like this -> C:\b`[a`]r♭\pr`[o`]file♭.txt,
# but I'm not sure when it is the same at -Path $tarpath

New-Item -ItemType SymbolicLink -Path $tarpath -Value $lnkpath

每当您在内置 cmdlet 上看到 -Path 参数时,假设它支持 wildcard globbing

这意味着[x]不是按字面解释,而是作为简单字符class的替代。在您的示例中,这意味着 C:\f[o]o♭\pr[o]file♭.txt 被解释为 C:\foo♭\profile♭.txt 这就是它抱怨目标路径不存在的原因。

要解决这个问题,请使用反引号 (`) 转义方括号:

New-Item -ItemType SymbolicLink -Path 'C:\f`[o`]o♭\pr`[o`]file♭.txt' -Value "C:\b[a]r♭\pr[o]file♭.txt"