1

How do I remove unnecessary dots in a file name in a windows batch script eg:

a.b.c.txt to a.txt
2

2 Answers 2

3

The info contained in the SS64 link that Charlie Wilson posted originated from my SU post: How does the Windows RENAME command interpret wildcards?. Unfortunately there isn't any simple REN syntax that can do what you want.

You will have to resort to at least one FOR loop. Here is one solution that works from the command prompt as long as none of your file names begin with ..

for %a in (*) do @for /f "eol=. delims=." %b in ("%a") do @ren "%a" "%b%~xa"

You can protect names that begin with . by using the following more complicated version:

for /f "eol=: delims=" %a in ('dir /b /a-d *^|findstr /blv .') do @for /f "eol=. delims=." %b in ("%a") do @ren "%a" "%b%~xa"

You can run either of the above commands from a batch file by changing all % to %%

0
0

The ren command. There is a very detailed explanation of using this command with wildcards at the link below.

Ren - Rename SS64.com

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .