Renaming file extension in batch

旧街凉风 提交于 2020-01-17 02:37:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!