How to rename multiple files with their first 19 characters

Hi guys,

I would like to rename multiple files by replacing the name by their first 19 characters of their old name.
Can you please assist.

Orginal file naming:
0000000000000376279.xml.3be03b33b7fd403bb03fe27fd1167ffc.error
0000000000000376280.xml.7c157a6cecf644cf934e919292339904.error
0000000000000376281.xml.80d7062d6cbc4c689d7c82c1e6ec35c7.error
. . .
. . .

I want to achieve:
0000000000000376279.xml
0000000000000376280.xml
0000000000000376281.xml
. . .

script used in CMD doesn't work
exception: command is incorrect

ren -n 's/(.{19}).*(\.error)$' *.xml

Open in new window


Thank you
Darius
DariusAsked:
Who is Participating?
 
Bill PrewCommented:
In DOS please try:

ren *.error ???????????????????.xml

Open in new window


»bp
0
 
Hello ThereSystem AdministratorCommented:
Use Powershell.
0
 
oBdACommented:
PowerShell in test mode; it will only show what it would rename. Remove the -WhatIf at the end to run it for real:
gci C:\Temp\*.error | ren -NewName {$_.Name -replace '\A(.*?\.xml)\..*', '$1'} -WhatIf

Open in new window

0
 
DariusAuthor Commented:
Thank you all for assistance...

Thanks to Hello There for advice to use Powershell.

Thanks oBdA. Code working successfully.

Thank you Bill for answer to my question.
1
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.