中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --

联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!

中国DOS联盟论坛
现在时间是 2026-06-15 23:45
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » 已结:将文件名改为001.txt 010.txt...100.txt 查看 1,497 回复 2
楼 主 已结:将文件名改为001.txt 010.txt...100.txt 发表于 2004-11-27 00:00 ·  中国 上海 电信
初级用户
积分 105
发帖 1
注册 2004-11-27 00:00
UID 34071
性别 男
状态 离线
有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 ]
2 发表于 2004-11-28 00:00 ·  中国 河北 石家庄 联通
铂金会员
★★★★
网络独行侠
积分 6,962
发帖 2,753
注册 2003-04-16 00:00
UID 1565
性别 男
来自 河北保定
状态 离线
提醒楼主写好求助帖子的标题,我是忽略了数次你的帖子后才进来的(详见我签名中的提示)。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命令的扩展功能。
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
3 发表于 2004-12-04 00:00 ·  中国 山西 运城 联通
元老会员
★★★★
Batchinger
积分 4,432
发帖 1,512
注册 2002-10-18 00:00
UID 19
性别 男
状态 离线
Re kanny10:

这是win9x下的方案,在nt系列下应该也能运行。


@echo off
if == goto %2
set prog=%0
if == call %prog% $ loop1 0 1 2 3 4 5 6 7 8 9
set prog=
goto end

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

:loop2
if == 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 == 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 ]
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
论坛跳转: