Board logo

标题: 【求助】for 循环里面怎么改变路径 [打印本页]

作者: terrytong     时间: 2008-9-5 11:33    标题: 【求助】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 ]
作者: terrytong     时间: 2008-9-5 12:57
后来我试试不用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 ]
作者: huahua0919     时间: 2008-9-5 14:07
用cd/d命令.