中国DOS联盟论坛

中国DOS联盟

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

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

游客:  注册 | 登录 | 命令行 | 会员 | 搜索 | 上传 | 帮助 »
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » 【求助】for 循环里面怎么改变路径
作者:
标题: 【求助】for 循环里面怎么改变路径 上一主题 | 下一主题
terrytong
中级用户





积分 240
发帖 115
注册 2008-3-10
状态 离线
『楼 主』:  【求助】for 循环里面怎么改变路径

帮我看看下面的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 ]

2008-9-5 11:33
查看资料  发送邮件  发短消息 网志   编辑帖子  回复  引用回复
terrytong
中级用户





积分 240
发帖 115
注册 2008-3-10
状态 离线
『第 2 楼』:  

后来我试试不用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 ]

2008-9-5 12:57
查看资料  发送邮件  发短消息 网志   编辑帖子  回复  引用回复
huahua0919
银牌会员




积分 1608
发帖 780
注册 2007-10-7
状态 离线
『第 3 楼』:  

用cd/d命令.

2008-9-5 14:07
查看资料  发送邮件  访问主页  发短消息 网志   编辑帖子  回复  引用回复

请注意:您目前尚未注册或登录,请您注册登录以使用论坛的各项功能,例如发表和回复帖子等。


可打印版本 | 推荐给朋友 | 订阅主题 | 收藏主题



论坛跳转: