powershell - 如何使用 powershell 确定特定的字符文件?
问题描述
我有一个文件。
c:\\[test^!#$%&'()=~{`}_+-^[];.,] test.xlsx
但powershell测试路径错误。
PS C:\\> Test-Path -LiteralPath "C:\\[test^!#$%&'()=~{`}_+-^[];.,] test.xlsx" -PathType Leaf
PS C:\\> False
PS C:\\> Test-Path "C:\\[test^!#$%&'()=~{`}_+-^[];.,] test.xlsx" -PathType Leaf
PS C:\\> False
有人对如何解决这个问题有一些想法吗?谢谢!
解决方案
首先,拥有这样的文件名是自找麻烦。他们带来的麻烦多于帮助。
话虽如此,Powershell引用规则解释了如何使用引号。由于文件名中有一个单引号,因此必须通过加倍来对其进行转义 - 通常的反引号在这里没有帮助。Here-Strings 也可以。像这样,
# single quote twice
test-path -literalpath '[test^!#$%&''()=~{`}_+-^[];.,] test.xlsx'
True
# here-string
test-path -literalpath @'
>> [test^!#$%&'()=~{`}_+-^[];.,] test.xlsx
>> '@
True
# here-string in varialbe
$f =@'
>> [test^!#$%&'()=~{`}_+-^[];.,] test.xlsx
>> '@
test-path -literalpath $f
True
推荐阅读
- google-cloud-platform - GCP 结算报告中的费用与导出到 GBQ 的费用不匹配
- c# - 如何提示用户输入 1 到 20 之间的数字
- swift - Swift Combine. What is a correct way to return from a block of a timeout handler?
- r - 处理完成的退出代码 PyCharm,而代码工作。R 编程
- linux - 在 Fedora 中,列出与 Package 关联的所有命令
- android - NativeScript 复制不同版本的 android 库
- mysql - mysql-从每个id中选择一个随机行
- c# - DynamoDB Scan 似乎无法识别我的列表
> - ansible - 检查两个变量是否都已定义且不为空
- elasticsearch - 从自定义 FieldBridge 索引 LongField 的问题