英文:
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>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论