【问题标题】:powershell to bulk remove certain character(s) from many filenames within multiple subfolderspowershell 从多个子文件夹中的许多文件名中批量删除某些字符
【发布时间】:2016-11-22 15:35:32
【问题描述】:

我已经研究过这个问题并仔细阅读了这里的知识库。我确实发现了一些涉及通过 PowerShell 删除文件/文件夹名称中的某些字符的主题。不幸的是,尝试执行以下 cmdlet 会导致以下错误。

cmd: Get-Item * | ForEach-Object {Rename-Item $_ ($_.Name -replace "%", "")}
error: rename-item: Source and destination path must be different

有成千上万个文件。我正在尝试从许多子文件夹中的任何和所有文件名中删除 %# 符号。

示例:之前

FileName%1%#1.doc

之后

FileName11.doc

【问题讨论】:

  • 你能添加完整的堆栈跟踪吗?

标签: powershell


【解决方案1】:

不要使用 cmd 而是使用 powershell。这是您示例中的正确语法:)

Get-Item * | ForEach-Object {Rename-Item $_ -NewName ($_.name -replace '#','' -replace '%','')}  

【讨论】:

  • 尝试后,我在PowerShell中仍然遇到以下错误: Rename-Item : Source and destination path must be different.在 line:1 char:30 + Get-Item * | ForEach-Object {Rename-Item $_ -NewName ($_.name -replace '#','' -r ... + ~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : WriteError: (G:\WESTWICKE\Sy...n Loren's Files: String) [Rename-Item] + FullyQualifiedErrorId : RenameItemIOError,Microsoft.PowerShell.Commands.RenameItemCommand
  • 尝试将-Force参数添加到rename-item
猜你喜欢
  • 2015-05-18
  • 2019-07-29
  • 1970-01-01
  • 2014-04-24
  • 1970-01-01
  • 1970-01-01
  • 2020-04-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多