标题: 幫忙縮短批次檔的內容或者優化
[打印本页]
作者: dosfroum
时间: 2005-10-30 21:34
标题: 幫忙縮短批次檔的內容或者優化
請問下面的寫法 有辦法優化 或者縮短呢
這次我的寫法 要是想到有地方要修改的話 很麻煩 要一次修改很多行
現在只有10個做又 要是擴增到50個 可能會改到發瘋
所以請教有無簡短的寫法
但是要達到相同的效果喔
感謝
:Second
cls
:ip33
if not "%ip33%"=="v" goto ip34
set ip=172.30.34.33
set PCNnumber=IP0000%ip:~-2%
net use \\%ip%\ipc$ %pass% /user:"%name%" >nul
call remote.bat
:ip34
if not "%ip34%"=="v" goto ip35
set ip=172.30.34.34
set PCNnumber=IP0000%ip:~-2%
net use \\%ip%\ipc$ %pass% /user:"%name%" >nul
call remote.bat
:ip35
if not "%ip35%"=="v" goto ip36
set ip=172.30.34.35
set PCNnumber=IP0000%ip:~-2%
net use \\%ip%\ipc$ %pass% /user:"%name%" >nul
call remote.bat
:ip36
if not "%ip36%"=="v" goto ip37
set ip=172.30.34.36
set PCNnumber=IP0000%ip:~-2%
net use \\%ip%\ipc$ %pass% /user:"%name%" >nul
call remote.bat
:ip37
if not "%ip37%"=="v" goto ip38
set ip=172.30.34.37
set PCNnumber=IP0000%ip:~-2%
net use \\%ip%\ipc$ %pass% /user:"%name%" >nul
call remote.bat
:ip38
if not "%ip38%"=="v" goto ip39
set ip=172.30.34.38
set PCNnumber=IP0000%ip:~-2%
net use \\%ip%\ipc$ %pass% /user:"%name%" >nul
call remote.bat
:ip39
if not "%ip39%"=="v" goto ip40
set ip=172.30.34.39
set PCNnumber=IP0000%ip:~-2%
net use \\%ip%\ipc$ %pass% /user:"%name%" >nul
call remote.bat
:ip40
if not "%ip40%"=="v" goto ip41
set ip=172.30.34.40
set PCNnumber=IP0000%ip:~-2%
net use \\%ip%\ipc$ %pass% /user:"%name%" >nul
call remote.bat
:ip41
if not "%ip41%"=="v" goto ip42
set ip=172.30.34.41
set PCNnumber=IP0000%ip:~-2%
net use \\%ip%\ipc$ %pass% /user:"%name%" >nul
call remote.bat
:ip42
if not "%ip42%"=="v" goto ip43
set ip=172.30.34.42
set PCNnumber=IP0000%ip:~-2%
net use \\%ip%\ipc$ %pass% /user:"%name%" >nul
call remote.bat
:ip43
if not "%ip43%"=="v" goto ip44
set ip=172.30.34.43
set PCNnumber=IP0000%ip:~-2%
net use \\%ip%\ipc$ %pass% /user:"%name%" >nul
call remote.bat
:ip44
if not "%ip44%"=="v" goto ip45
set ip=172.30.34.44
set PCNnumber=IP0000%ip:~-2%
net use \\%ip%\ipc$ %pass% /user:"%name%" >nul
call remote.bat
:ip45
if not "%ip45%"=="v" goto ip46
set ip=172.30.34.45
set PCNnumber=IP0000%ip:~-2%
net use \\%ip%\ipc$ %pass% /user:"%name%" >nul
call remote.bat
:ip46
if not "%ip46%"=="v" goto ip47
set ip=172.30.34.46
set PCNnumber=IP0000%ip:~-2%
net use \\%ip%\ipc$ %pass% /user:"%name%" >nul
call remote.bat
:ip47
if not "%ip47%"=="v" goto ip48
set ip=172.30.34.47
set PCNnumber=IP0000%ip:~-2%
net use \\%ip%\ipc$ %pass% /user:"%name%" >nul
call remote.bat
:ip48
if not "%ip48%"=="v" goto ip49
set ip=172.30.34.48
set PCNnumber=IP0000%ip:~-2%
net use \\%ip%\ipc$ %pass% /user:"%name%" >nul
call remote.bat
:ip49
if not "%ip49%"=="v" goto ip50
set ip=172.30.34.49
set PCNnumber=IP0000%ip:~-2%
net use \\%ip%\ipc$ %pass% /user:"%name%" >nul
call remote.bat
:ip50
if not "%ip50%"=="v" goto ip84
set ip=172.30.34.50
set PCNnumber=IP0000%ip:~-2%
net use \\%ip%\ipc$ %pass% /user:"%name%" >nul
call remote.bat
:ip84
if not "%ip84%"=="v" goto ipend
set ip=172.30.34.84
set PCNnumber=IP000%ip:~-2%
net use \\%ip%\ipc$ %pass% /user:"%name%" >nul
call remote.bat
:ipend
rem ****************************************************************************************
goto _ProgramList
——————————————— Edited by willsort ———————————————
原标题:幫忙縮短批次檔的內容或者優化
为了方便广大用户的浏览和版主管理,请注意标题应该是对内容的提炼和概括
请楼主在标题中简要注明批处理的功用
——————————————— Edited by willsort ———————————————
[
Last edited by willsort on 2005-10-31 at 15:16 ]
作者: 本是
时间: 2005-10-31 12:19
试试这样改:
:Second
cls
:setupipnn
::for %%i in (1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) set ipnn=ip%%i
for %%i in (32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51) set ipnn=ip%%i
::for %%i in (52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71) set ipnn=ip%%i
if not "%ipnn%"=="v" goto ipend
set ip=172.30.34.%ipnn%
set PCNnumber=IP0000%ip:~-2%
net use \\%ip%\ipc$ %pass% /user:"%name%" >nul
call remote.bat
:ipend
rem ***********************************************************
goto _ProgramList
另外,你的姓名是不是打错了?应该是DOS论坛
dosforum吧!
[
Last edited by 本是 on 2005-10-31 at 12:24 ]
作者: willsort
时间: 2005-10-31 14:06
Re 本是:
兄的代码应该有些问题,for语句因缺乏do关键字会产生语法错误;同时,for只是单纯循环了set ipnn,而与以下的各句代码均没有关系。
Re dosfroum:
问题的关键在于 %ip33% 等环境变量的替换和引用,解决了这个问题,其他就都迎刃而解了。
以下是我的方案:方案一使用了for内嵌代码,必须启用变量延迟特性,因此 setlocal 一句是必要的;方案二使用了call子程序,call所产生的子环境具有“变量延迟”特性,因此其 setlocal 语句是可省略的,便于某些场合内的应用。
至于对类似 %ip33% 的引用,使用了二次转义的办法,即在调用echo一句时实现第一次转义,%%ip%%n%% ==> %ip33%;调用 call _calltemp.bat 一句时实现第二次转义,%ip33% 替换为所引用的字符串值。
:: Netip.cmd
:: Will Sort - 2005-10-31 - CMD@WinXP
@echo off & setlocal EnableDelayedExpansion
:Second
cls
for /l %%n in (33,1,84) do (
echo @if "%%ip%%n%%"=="v" set _v=true> _calltemp.bat
call _calltemp.bat
if "!_v!"=="true" (
set ip=172.30.34.%%n
set PCNnumber=IP0000!ip:~-2!
net use \\%ip%\ipc$ %pass% /user:"%name%" >nul
call remote.bat
set _v=
)
)
:ipend
rem ****************************************************************************************
goto _ProgramList
:: Netip2.cmd
:: Will Sort - 2005-10-31 - CMD@WinXP
@echo off
setlocal
:Second
cls
:IPCheck
echo @if "%%ip%1%%"=="v" set _v=true> _calltemp.bat
call _calltemp.bat
if not "%_v%"=="true" goto :EOF
set ip=172.30.34.%1
set PCNnumber=IP0000%ip:~-2%
echo ip=%ip% pn=%PCNnumber%
net use \\%ip%\ipc$ %pass% /user:"%name%" >nul
call remote.bat
set _v=
goto :EOF
for /l %%n in (33,1,84) do call:IPCheck %%n
:ipend
rem ****************************************************************************************
goto _ProgramList
作者: smileseeker
时间: 2005-11-1 23:04
for /l %%n in (33,1,84) do call:IPCheck %%n
原来还可以这样call:IPCheck %%n
学习ing。。。。。。
[
Last edited by smileseeker on 2005-11-1 at 23:05 ]