中国DOS联盟

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

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

中国DOS联盟论坛
现在时间是 2026-08-12 23:19
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » 怎样把批处理中的文件路径放到配置文件中读取? 查看 650 回复 3
楼 主 怎样把批处理中的文件路径放到配置文件中读取? 发表于 2010-01-08 09:04 ·  中国 广东 深圳 罗湖区 电信
初级用户
积分 29
发帖 29
注册 2008-11-18 16:19
17年会员
UID 131353
性别 男
状态 离线
我目前的批处理是这样的:

@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

我的批处理该怎样改进一下啊?多谢了!
2 发表于 2010-01-08 09:30 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
积分 3,105
发帖 1,276
注册 2008-03-08 13:00
18年会员
UID 112398
性别 男
状态 离线

@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 ]
本帖最近评分记录 (共 1 条) 点击查看详情
评分人分数时间
boy +1 2010-01-08 12:07
批处理之家新域名:www.bathome.net
3 发表于 2010-01-08 10:28 ·  中国 广东 深圳 罗湖区 电信
初级用户
积分 29
发帖 29
注册 2008-11-18 16:19
17年会员
UID 131353
性别 男
状态 离线
现在在运行的时候,会提示?:
"目标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 ]
4 发表于 2010-01-08 12:06 ·  中国 广东 深圳 罗湖区 电信
初级用户
积分 29
发帖 29
注册 2008-11-18 16:19
17年会员
UID 131353
性别 男
状态 离线
搞定!~ 多谢bat-zw
论坛跳转: