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
>Solution :
The .Name property includes the filename extension. Use .BaseName and .Extension separately:
$files | Rename-Item -NewName { $_.BaseName.TrimStart('0')+'_16' + $_.Extension }