0

I've got a few files like this:

files

I'm wanting to change them all to *.gz

This is the code I've written to try to change the file extensions:

ren *.dat.gz.gz.gz.gz *.gz

But this doesn't do anything. Thanks.

user1009569
  • 477
  • 6
  • 22
  • http://superuser.com/questions/608128/how-to-batch-rename-and-remove-last-characters – Alex K. Mar 28 '14 at 16:23
  • @AlexK. - Actually that link did not have an optimal answer. I've since added a much simpler solution using only a single REN command :-) It is basically the same as MC ND's answer. – dbenham Mar 29 '14 at 02:40

3 Answers3

1
ren ????????.dat.gz.* ????????.gz

or, if the .dat part is needed

ren ????????.dat.gz.* ????????.dat.gz
MC ND
  • 69,615
  • 8
  • 84
  • 126
0

Try this:

@echo off
setlocal enabledelayedexpansion

for %%a in (*.gz) do (
   set "file=%%a" 
   set "file=!file:.gz.gz.gz=!"
   echo ren "%%~nxa" "!file!"
)

Run it from the location of the .gz files. Remove the Echo when the screen output looks right.

Matt Williamson
  • 6,947
  • 1
  • 23
  • 36
0

It works too:

@echo off
for /f %%a in ('dir /b /s *.gz') do (
 for /f "delims=. tokens=1" %%b in ('echo/%%~na') do (ren "%%a" "%%b.gz")
)
Rafael
  • 3,042
  • 3
  • 20
  • 36