使用静态文本重命名文件,删除 ‘0’ 后。

huangapple go评论61阅读模式
英文:

Rename files with Static text after removing '0'

问题

这是您要翻译的部分:

"000145
000029

I am able to remove the zero for the file name with this script and also want to add _16 in the filename while renaming and the file should be like this 145_16 or 29_16.

$files = Get-ChildItem -File -Filter 0* $files |Rename-Item -NewName { $_.Name.TrimStart('0')+"_16";}

But after renaming the file is showing the .jpg also in the filename. Here is the example

145.jpg_16 or 29.jpg_16

Can anyone please help me to resolve this"

英文:

I have few files starting with zero like this

000145
000029

I am able to remove the zero for the file name with this script and also want to add _16 in the filename while renaming and the file should be like this 145_16 or 29_16.

$files = Get-ChildItem -File -Filter 0*
$files |Rename-Item -NewName { $_.Name.TrimStart('0')+"_16"}

But after renaming the file is showing the .jpg also in the filename. Here is the example

145.jpg_16 or 29.jpg_16

Can anyone please help me to resolve this

答案1

得分: 1

.Name属性包括文件扩展名。分别使用.BaseName.Extension

$files | Rename-Item -NewName { $_.BaseName.TrimStart('0')+'_16' + $_.Extension }
英文:

The .Name property includes the filename extension. Use .BaseName and .Extension separately:

$files | Rename-Item -NewName { $_.BaseName.TrimStart('0')+'_16' + $_.Extension }

</details>



huangapple
  • 本文由 发表于 2023年2月8日 12:07:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/75381299.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定