PowerShell 重命名文件名并保留扩展名 [英] PowerShell Rename file name and keep extension
本文介绍了PowerShell 重命名文件名并保留扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在这里找到了可以满足我需要的代码
I have found code on here which does what I need it to it
$files = gci -filter "*.txt" |select fullname
foreach ($file in $files) {
$filename = $file.fullname
$newFilename = $filename.Replace(".", " ")
rename-item $filename $newFilename
}
我需要代码来更改文件名并保留文件扩展名.上面的代码替换了."和 " ".我可以对其进行编码以再次重命名文件以重新添加扩展名.只是想看看有没有更好的方法.
I require the code to change the file name and keep the file extension. The code above replaces "." with " ". I can code it to rename the file again to add the extension back. Just wanted to see if there was a better way to do it.
干杯
推荐答案
Change 'old'
&'new'
随心所欲删除 -Whatif
以应用命令.
Change 'old'
& 'new'
to whatever you want
Remove the -Whatif
to apply the command.
Get-ChildItem -Path C:\temp\files -Filter *.txt |
Rename-Item -NewName {$_.Basename.Replace("old","new") + $_.extension} -WhatIf -Verbose
这篇关于PowerShell 重命名文件名并保留扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文