【发布时间】:2020-09-03 10:57:51
【问题描述】:
我想替换我文件中的某些字符 例如
我想改变>“原始”->“其他东西”
我使用此脚本仅使用 powershell 将其替换到一个文件夹中
Dir |>> Rename-Item -NewName { $_.Name -replace "original","something " }
问题是,使用该代码,仅替换一个文件夹中的文件,而不替换子文件夹中的文件 我需要它来替换它在文件夹和子文件夹文件中的文件,这可能吗?
(我对这个有点陌生)
注意:当文件中有任何子文件夹时,此代码会显示此错误
错误 =
Rename-Item : Source and destination path must be different.
At line:2 char:1
+ Rename-Item -NewName { $_.Name -replace "original","something " }
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (F:\folder-name\...ff\py-compat:String) [Rename-Item], IOException
+ FullyQualifiedErrorId : RenameItemIOError,Microsoft.PowerShell.Commands.RenameItemCommand
操作系统:windows
信息
操作系统型号:windows 10
【问题讨论】:
-
段落的第二行:快速修复>我要更改>“原始”->“某事”
-
Get-ChildItem -Path 'TheRootFolder' -File -Recurse | Rename-Item -NewName ($_.Name -replace 'original', 'something')
标签: windows powershell replace directory