Board logo

标题: 怎样把批处理中的文件路径放到配置文件中读取? [打印本页]

作者: boy     时间: 2010-1-8 09:04    标题: 怎样把批处理中的文件路径放到配置文件中读取?

我目前的批处理是这样的:

@echo off
set date=%~1
ping /n 83 127.1>nul
IF EXIST k:\public_html\website\nul rd k:\public_html\website /s/q
start /b xcopy /s/r/y/h/c D:\Inetpub\wwwroot\whbcn\public_html\*.* k:\public_html\>D:\Inetpub\wwwroot\whbcn\website_design\Log\updateServerB\%date%.log
goto :eof
exit

我想将里面几个路径放到一个配置文件中,而不是象现在一样写死在批处理里面.
比如配置文件fileConfig.ini内容:
BServerPathWeb=k:\public_html\website
AServerPath=D:\Inetpub\wwwroot\whbcn\public_html
BServerPath=k:\public_html
updateServerBLogPath=D:\Inetpub\wwwroot\whbcn\website_design\Log\updateServerB

我的批处理该怎样改进一下啊?多谢了!
作者: bat-zw     时间: 2010-1-8 09:30

@echo off
for /f "delims=" %%a in (config.ini) do set "%%a"
set "dates=%~1"&rem 请不要将变量写成系统变量名
ping /n 83 127.1>nul
if exist "%BServerPathWeb%" rd /s /q "%BServerPathWeb%"
start /b xcopy /s /r /y /h /c "%AServerPath%\*.*" "%BServerPath%\>%updateServerBLogPath%\%dates%.log"
[ Last edited by bat-zw on 2010-1-8 at 10:43 ]
作者: boy     时间: 2010-1-8 10:28
现在在运行的时候,会提示?:
"目标k:\public_html\>D:\Inetpub\wwwroot\whbcn\website_design\Log\updateServerB\%date%.log 是文件名还是目录名 <F = 文件. D = 目录>?"
怎样去掉提示啊?而且现在并没有把旧的文件夹k:\public_html\website删掉,也没有拷贝路径D:\Inetpub\wwwroot\whbcn\public_html\下的所有文件到k:\public_html\下.

修改后的文件:
@echo off
for /f "delims=" %%a in (pathConfig.ini) do set "%%a"
set "dates=%~1"&rem
ping /n 83 127.1>nul
if exist "%BServerPathWeb%\nul" rd /s/q "%BServerPathWeb%"
start /b xcopy /s/r/y/h/c "%AServerPath%\*.*" "%BServerPath%\>%updateServerBLogPath%\%dates%.log"
goto :eof
exit
谢谢!

[ Last edited by boy on 2010-1-8 at 10:33 ]
作者: boy     时间: 2010-1-8 12:06
搞定!~ 多谢bat-zw