PowerShell Rename-Item on Long Named Files Warning Removal

PowerShell Rename-Item on Long Named Files Warning Removal

我尝试使用 PwerShell Rename-Item cmdlet 重命名文件。下面的代码

Get-ChildItem -recurse * `
  | ?{!$_.PsIsContainer} `
  | Rename-Item -NewName {$_.FullName -Replace '.abcd@email.com','.abcd@email_A.com.abcd@email_B.com.abcd@email_E.com'}

但是,PowerShel 告诉我长路径或文件名;这与我的过程无关。但强烈需要保留新的长名称。

如何排除这个错误?

是否可以向您询问代码示例?以下评论代码片段(保守方法)可能会有所帮助:

Get-ChildItem -recurse * | Where-Object {!$_.PsIsContainer} | 
  ForEach-Object {
    ###  in regular expression:  ↓           ↓   escape dots
    $NewName = $_.Name -Replace '\.abcd@email\.com',
      '.abcd@email_A.com.abcd@email_B.com.abcd@email_E.com'

    ### here is right place to check target filename length:
    $targetLength = 1 + $_.DirectoryName.Length + $NewName.Length

    Rename-Item -Path $_.FullName -NewName $NewName
  }

阅读Rename-Item reference and Regular Expression Language - Quick Reference