2016-08-24 84 views
0

在下面的半伪代码中,数组$system中第一个元素的正斜杠总是作为反斜杠读取。转义前斜杠问题

我尝试了各种转义字符,如`和\但无济于事。这是PowerShell中的一个已知问题吗?怎么解决?

$system = @("Something/Anything", "Super Development","Quality Assurance") 

//the following is looped with $y 
$string| ConvertTo-json | FT | Out-File -append C:\Test\Results\$($system[$y])_All.csv 

//error: 
Message  : Could not find a part of the path 'C:\Test\Results\Something\Anything_All.csv' 
+3

在Windows中,你不能在文件命名“/”使用! – autosvet

+0

'$东西[$ Y]'似乎并没有解决我 '$东西= '测试 - ' 的foreach($ Y $中的系统){$ 东西[$ Y] }' –

+0

@HiteshDhruna什么对不起,错字。固定 – rafvasq

回答

2

正如在评论你的问题已经提到@autosvet有几个reserved characters无法在Windows文件名/路径,即使用:

  • 使用的任何字符当前代码页的名称包括Unicode字符和扩展字符集中的字符(128-255),但以下情况除外:

    以下保留字符:

    • <(小于)
    • >(大于)
    • :(结肠)
    • "(双引号)
    • /(正斜杠)
    • \(反斜杠)
    • |(垂直条或pi PE)
    • ?(问号)
    • *(星号)

这些字符无法逃脱,只能更换。您可以使用GetInvalidFileNameChars()方法程序确定需要更换的人物:

$invalid = [regex]::Escape([IO.Path]::GetInvalidFileNameChars()) 
$string | ConvertTo-json | FT | 
    Out-File -Append C:\Test\Results\$($something[$y] -replace $invalid, '_')_All.csv 
+0

感谢您对我删除的问题Ansgar的提示。我没有注意到这些都是CSV的所有名称... –