中国DOS联盟

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

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

中国DOS联盟论坛
现在时间是 2026-08-09 14:40
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » 【求助】for 循环里面怎么改变路径 查看 666 回复 2
楼 主 【求助】for 循环里面怎么改变路径 发表于 2008-09-05 11:33 ·  中国 上海 上海地面通信息网络有限公司
中级用户
★★
积分 240
发帖 115
注册 2008-03-10 19:31
18年会员
UID 112561
性别 男
状态 离线
帮我看看下面的P啊,不知道为什么不能在For里面改路径啊?

@echo off
title set Copy file
mode con cols=100 lines=20
setlocal enabledelayedexpansion
if exist U:\terry\terry.txt goto start
net use u: \\10.5.1.101\testlog npg /user:administrator
if not exist U:\terry\terry.txt goto nonet

:start
d:
set tm=%time:~0,2%%time:~3,2%
set dt=%date:~10,4%%date:~4,2%%date:~7,2%
set new=%tm: =0%
for /r d: %%a in (*.cfg) do (
set n=0
set temp=%%a
set defin=!temp:~7,3!
if !defin!==Rev (
set mo=!temp:~19,9!
set dirc=!temp:~0,29!) else (
set mo=!temp:~21,9!
set dirc=!temp:~0,31!)
cd !dirc!
for /f "skip=10 tokens=1,2 delims==" %%b in (SFIS.cfg) do (
set /a n+=1
set temp2=%%c
if "!n!"=="1" set phase=!temp2!&&echo phase=!phase!)
cd !dirc!log
for /r %%d in (*.log) do (
set temp3=%%d
set name=!temp3:~33,8!
CALL CALL !!!!new!!!!
if !new!==0000 (
ren !name!.log !name!-!mo!--!phase!.log
copy !name!-!mo!--!phase!.log E:\testlog
copy !name!-!mo!--!phase!.log U:\CastlePoint_Intel)
)
cd !dirc!testlog
if not exist *.txt goto end
for /r %%e in (*.txt) do (
set temp4=%%e
set name2=!temp4:~37,7!
ren !name2!.txt !name2!--!dt!!new!.txt
copy !name2!--!dt!!new!.txt E:\testlog
copy !name2!--!dt!!new!.txt U:\CastlePoint_Intel&&del !name2!--!dt!!new!.txt)
)
goto :end


:nonet
color 47
echo *********************************************************************************
Echo.
Echo.
Echo.
Echo.
Echo.
echo the network is not available, please check if the U: is accessable and then try again
Echo.
Echo.
Echo.
Echo.
echo *********************************************************************************
ping/n 4 127.4>nul



:end

[ Last edited by terrytong on 2008-9-5 at 12:52 PM ]
2 发表于 2008-09-05 12:57 ·  中国 上海 上海地面通信息网络有限公司
中级用户
★★
积分 240
发帖 115
注册 2008-03-10 19:31
18年会员
UID 112561
性别 男
状态 离线
后来我试试不用CD
for /f "skip=10 tokens=1,2 delims==" %%b in (SFIS.cfg) do (
set /a n+=1
set temp2=%%c
if "!n!"=="1" set phase=!temp2!&&echo phase=!phase!)
这句可以正确运行.
但是下面两个For都不行,
for /r !dirc!log %%d in (*.log) do (
set temp3=%%d
set name=!temp3:~33,8!
CALL CALL !!!!new!!!!
if !new!==0000 (
ren !name!.log !name!-!mo!--!phase!.log
copy !name!-!mo!--!phase!.log E:\testlog
copy !name!-!mo!--!phase!.log U:\CastlePoint_Intel)
)
for /r !dirc!testlog %%e in (*.txt) do (
set temp4=%%e
set name2=!temp4:~37,7!
ren !name2!.txt !name2!--!dt!!new!.txt
copy !name2!--!dt!!new!.txt E:\testlog
copy !name2!--!dt!!new!.txt U:\CastlePoint_Intel&&del !name2!--!dt!!new!.txt)

高手们帮忙点拔下啊。

[ Last edited by terrytong on 2008-9-5 at 12:59 PM ]
3 发表于 2008-09-05 14:07 ·  中国 江苏 苏州 中移铁通
银牌会员
★★★
积分 1,608
发帖 780
注册 2007-10-07 10:19
18年会员
UID 99089
性别 男
状态 离线
用cd/d命令.
论坛跳转: