我有一条看起来像这样的路径:
$path = path\to\weird\filename\PUBLISERET - Dalager 1, Brøndby - Leveringsaftale D12-24311 1.0.pdf
当我这样做时:
Set-ItemProperty -LiteralPath $path -Name IsReadOnly -Value $true
我告诉我路径不存在,即使它确实存在。我相信这是因为文件名。我该怎么办?
答案 0 :(得分:2)
尝试在路径上放置单引号。
$path = 'path\to\weird\filename\PUBLISERET - Dalager 1, Brøndby - Leveringsaftale D12-24311 1.0.pdf'
答案 1 :(得分:1)
Dmitriy Kapitanov's answer是正确的:在路径周围加上单引号。的证明强>:
PS D:\PShell> $path = 'D:\bat\Unusual Names\Türkçe (Türkiye)\PUBLISERET - Dalager 1, Brøndby - Leveringsaftale D12-24311 1.0.pdf'
PS D:\PShell> Get-ItemProperty $path
Directory: D:\bat\Unusual Names\Türkçe (Türkiye)
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 31.08.2015 17:55 34429 PUBLISERET - Dalager 1, Brøndby - Leveringsaftale
D12-24311 1.0.pdf
PS D:\PShell> Set-ItemProperty -LiteralPath $path -Name IsReadOnly -Value $true
PS D:\PShell> Get-ItemProperty $path
Directory: D:\bat\Unusual Names\Türkçe (Türkiye)
Mode LastWriteTime Length Name
---- ------------- ------ ----
-ar-- 31.08.2015 17:55 34429 PUBLISERET - Dalager 1, Brøndby - Leveringsaftale
D12-24311 1.0.pdf
PS D:\PShell>