【问题标题】:PowerShell get-childitem cannot handle filename starting with [ character even with escape character即使使用转义字符,PowerShell get-childitem 也无法处理以 [ 字符开头的文件名
【发布时间】:2012-03-19 11:38:40
【问题描述】:

我在 c:\temp 目录中有一个名为 [default].xml 的文件。 当我在 powershell 控制台中发出命令:get-childitem "c:\temp`[default].xml" 时,它什么也没给我。但是,如果我发出这个命令:get-childitem "c:\temp*default].xml",它会按预期工作。

为什么“[”上的转义字符不起作用?

【问题讨论】:

    标签: powershell escaping character


    【解决方案1】:

    您在旧的Technet Windows PowerShell Tip of the Week 中获得了 Microsoft 官方答案。

    你可以使用:

    Get-ChildItem 'c:\temp\``[default``].xml'
    

    【讨论】:

      【解决方案2】:

      查看关于_wildcards 的获取帮助

      [] 是通配符“通配符”运算符。要对包含这些字符的文件使用 get-childitem,请使用 -literalpath 开关禁用文件规范的通配符:

      get-childitem -literalpath "c:\temp[default].xml"
      

      另外,普通的通配符仍然可以在 directoryinfo 对象的 .getfiles() 方法中使用:

      (get-item c:\).getfiles("temp[default].*")
      

      【讨论】:

        猜你喜欢
        • 2011-08-06
        • 1970-01-01
        • 2010-09-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-01-21
        • 1970-01-01
        • 2012-10-12
        相关资源
        最近更新 更多