Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

a.b.c.txt to a.txt
share|improve this question
    
Possible duplicate: superuser.com/questions/222091/… –  bytebuster Dec 2 '12 at 9:46
    
That is not a duplicate, though it might provide hints on a possible way to solve the problem. –  dbenham Dec 2 '12 at 15:07

2 Answers 2

up vote 4 down vote accepted

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 %%

share|improve this answer
    
That works. Thanks a lot –  Sab Dec 7 '12 at 7:30

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

Ren - Rename SS64.com

share|improve this answer
1  
The information on SS64 originated from my SU post - How does the Windows RENAME command interpret wildcards?. I encouraged Simon to post the info on SS64 in this post: Updated wildcard rules, especially for REN. He kindly includes a credit at the bottom of the SS64 REN page. –  dbenham Dec 2 '12 at 13:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.