Board logo

标题: 已结:将文件名改为001.txt 010.txt...100.txt [打印本页]

作者: kanny10     时间: 2004-11-27 00:00    标题: 已结:将文件名改为001.txt 010.txt...100.txt

有100个文本文件,文件名是1.txt-100.txt 现在在要将文件名改为001.txt 010.txt 100.txt 怎么写???
以下是我写的,不过有错误
set /a beg=1
set /a end=001
:round1
if %beg% GEQ 10 (goto round2)else (
ren h:\%beg%.txt  %end%.txt-------------------------------这里有问题 ,可是我不会解决 请教高手
set /a beg=%beg%+1
set /a  end=%end%+001
goto round1
)
:round2
pause


——————————————  willsort 版务记录  ——————————————
修改原标题:dos批处理问题 急!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
——————————————  willsort 版务记录  ——————————————


[ Last edited by willsort on 2005-11-26 at 17:30 ]
作者: Climbing     时间: 2004-11-28 00:00
提醒楼主写好求助帖子的标题,我是忽略了数次你的帖子后才进来的(详见我签名中的提示)。Doit.cmd:
@echo off
if %1#==# goto _quit
set n=%1
if %n% LSS 10 goto _lss10
if %n% LSS 100 goto _lss100
goto _quit:_lss10
if exist %n%.txt ren %n%.txt 00%n%.txt
if exist 00%n%.txt echo 成功将%n%.txt改名为00%n%.txt!
goto _quit:_lss100
if exist %n%.txt ren %n%.txt 0%n%.txt
if exist 0%n%.txt echo 成功将%n%.txt改名为0%n%.txt!
goto _quit:_quit
编辑好doit.cmd后,在当前目录下执行下面的命令:
for /L %i in (1,1,99) do @call doit.cmd %i这个批处理只能运行在2000/xp/2003这一类的系统下,因为它利用到了if及for命令的扩展功能。
作者: willsort     时间: 2004-12-4 00:00
Re kanny10:

    这是win9x下的方案,在nt系列下应该也能运行。
@echo off
if [%1]==[$] goto %2
set prog=%0
if [%1]==[] call %prog% $ loop1 0 1 2 3 4 5 6 7 8 9
set prog=
goto end

:loop1
if [%3]==[] goto end
::if exist %3*.txt
if [%3]==[0] call %prog% $ loop2 0 1 2 3 4 5 6 7 8 9
if not [%3]==[0] call %prog% $ loop3 %30 %31 %32 %33 %34 %35 %36 %37 %38 %39
shift
goto loop1

:loop2
if [%3]==[] goto end
if exist %3.txt ren %3.txt 00%3.txt
if not exist 00%3.txt echo Can't rename '%3.txt'
::echo rename '%3.txt' to '00%3.txt'>>out.txt
shift
goto loop2

:loop3
if [%3]==[] goto end
if exist %3.txt ren %3.txt 0%3.txt
if not exist 0%3.txt echo Can't rename '%3.txt'
::echo rename '%3.txt' to '0%3.txt'>>out.txt
shift
goto loop3
:end
[ Last edited by willsort on 2005-11-26 at 17:25 ]