Board logo

标题: [讨论]批处理规律字符处理 [打印本页]

作者: GOTOmsdos     时间: 2007-3-2 06:55    标题: [讨论]批处理规律字符处理

怎样用批处理对下面的的文件名实现两个任务:
1:
去掉前面的"GAME"
2
把1改成01,2改成02......
3
按照1,2,3的数字大小的顺序重新命名为A,B,C.......
比如: GAME1.MID 改为GAMEA.MID.......

以下是文件夹中的文件:
GAME1.MID
GAME10.MID
GAME11.MID
GAME12.MID
GAME13.MID
GAME14.MID
GAME15.MID
GAME16.MID
GAME17.MID
GAME18.MID
GAME19.MID
GAME2.MID
GAME20.MID
GAME21.MID
GAME22.MID
GAME23.MID
GAME24.MID
GAME3.MID
GAME4.MID
GAME5.MID
GAME6.MID
GAME7.MID
GAME8.MID
GAME9.MID

[ Last edited by GOTOmsdos on 2007-3-2 at 03:51 PM ]
作者: tao0610     时间: 2007-3-2 07:32

@echo off&setlocal enabledelayedexpansion
for /f %%a in ('dir/b *.MID') do (
                                   set tmp=%%~na
                                   set tmp=!tmp:GAME=!
                                   if !tmp! lss 10 set tmp=0!tmp!
                                   ren %%~a !tmp!%%~xa
                                  )
3
按照1,2,3的数字大小的顺序重新命名为A,B,C.......???
不太懂..
作者: namejm     时间: 2007-3-2 09:03
  这三个任务应该是分次完成的吧?如果是一次性完成的话,第2个任务就没必要了。

  另,这是某个文件夹下的所有文件还是某个文本中的记录?
作者: zh159     时间: 2007-3-2 10:58

@echo off&setlocal enabledelayedexpansion
for /f %%a in ('dir/b *.MID') do (
  set str=%%~na
  set str=!str:GAME=!
  call :A-Z
  ren %%~a !str!%%~xa
)
exit

:A-Z
set N=0
for /f %%n (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
  set /a N+=1
  if "!str!" == "!N!" set str=%%n&goto :eof
)
goto :eof

作者: everest79     时间: 2007-3-3 06:00

set a=xabcdefghi
for /f "delims=GAME." %%i in ('dir /b game*.mid') do (
set /a b=%%i%%10,c=%%i/10
call :rrr %%i %%b%% %%c%%)
goto :eof
:rrr
call echo ren game%1.mid game%3%%a:~%2,1%%.mid
goto :eof
发现一个好玩的

ren game*.mid "    *.mid"