Question

I have thousands of file with file extensions like this

3_bedroom_villas_in_chennai.html__201308050010_
3_bedroom_villas_in_chennai.html__201308080012_
3_bedroom_villas_in_chennai.html__201308100012_
3_bedroom_villas_in_chennai.html__201308110034_ and so on.....

inside a directory. I wanna change all these into the following

3_bedroom_villas_in_chennai__201308050010_.html
3_bedroom_villas_in_chennai__201308080012_.html
3_bedroom_villas_in_chennai__201308100012_.html
3_bedroom_villas_in_chennai__201308110034_.html

When I tried doing it in windows using the following command

ren *.* *.html

I got the following

A duplicate file name exists, or the file
cannot be found.
A duplicate file name exists, or the file
cannot be found.
A duplicate file name exists, or the file
cannot be found.
A duplicate file name exists, or the file
cannot be found. and so on...

Because I know that it will try to change everything into a single file name like

3_bedroom_villas_in_chennai.html and so on... 

any ways to do this either on windows or linux ??

Was it helpful?

Solution

In Linux:

ls | xargs -I % mv % %.html

ls command output is piped to xargs, and xargs replaces all % (after mv) with the input from ls

Also, if you want recursively go through all sub-directories, you might want to use:

find . -type f | xargs -I % mv % %.html

And in Windows:

for /r %x in (*) do ren "%x" *.txt

OTHER TIPS

using renamer:

$ renamer --regex --find '(.*).html(.*)' --replace '$1$2.html' *

Works on Windows, Mac and Linux.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top