批处理重命名文件

来源:百度知道 编辑:UC知道 时间:2024/05/22 06:24:48
同一文件夹下有30个文件不同后缀的文件,
10个一组,
例如bottle.* type.* can.*三组文件,
我需要重命名前缀改为bottle_cc.* type_cc.* can_cc.*
然后把每组文件放入指定的3个文件夹,
ren bottle.* bottle_cc.*
ren type.* type_cc.*
ren can.*3 can_cc.*3
请问怎么实现,命名后放入指定文件夹?

@echo off
if not exist bottle md bottle
if not exist type md type
if not exist can md can
for /f "delims=" %%a in ('dir /a-d /b *.*') do (
for %%i in (boottle type can) do (
if %%~na==%%i (
ren "%%a" "%%i_cc%%~xa"
move "%%i_cc%%~xa" %cd%\%%i
)))
pause

你得先建好那个文件夹:
copy bottle_cc.* 路径 要存放文件夹的名
例如:d:\>copy bottle_cc.* f:\abc

以此类推

@echo off
if not exist bottle md bottle
if not exist type md type
if not exist can md can
for /f "tokens=1,2 delims=." %%i in ('dir /a-d/b') do (
ren %%i.%%j %%i_cc.%%j
if %%i==bottle move %%i_cc.%%j bottle
if %%i==type move %%i_cc.%%j type
if %%i==can move %%i_cc.%%j can
)