问题
I've got a few files like this:
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.
回答1:
ren ????????.dat.gz.* ????????.gz
or, if the .dat part is needed
ren ????????.dat.gz.* ????????.dat.gz
回答2:
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.
回答3:
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")
)
来源:https://stackoverflow.com/questions/22717482/renaming-file-extension-in-batch