【问题标题】:File with no extension not changing on powershell没有扩展名的文件在powershell上没有改变
【发布时间】:2014-04-24 02:02:16
【问题描述】:

我有以下代码:

Get-ChildItem . *. | Rename-Item -NewName {$_.Name -replace 'line21','line21.map52'}

产生这个错误:

file: line21 is currently of type File (No extension).

当尝试将其更改为另一个扩展时,它不会更改。

但是,对于相同的场景,如果我使用另一个文件,它会工作得很好:

Get-ChildItem . *. | Rename-Item -NewName {$_.Name -replace 'line22.txt','line22.map52'}

【问题讨论】:

    标签: powershell powershell-2.0 powershell-remoting powershell-ise


    【解决方案1】:

    这种行为正在发生,因为您的Get-ChildItem 命令仅检索名称与*. 匹配的文件/文件夹。文件名“line21”与*. 不匹配,因此被排除在外。

    把你的命令改成这样:

    Get-ChildItem -Path . -Include * | Rename-Item -NewName {$_.Name -replace 'line21','line21.map52'};
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-12-24
      • 1970-01-01
      • 1970-01-01
      • 2023-01-13
      • 2017-06-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多