中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-09-23 22:09
47,812 topics / 349,917 posts / today 0 new / 48,274 members
DOS批处理 & 脚本技术(批处理室) » Ask: Batch processing for judging file content and character replacement
Printable Version  4,775 / 16
Floor16 youxi01 Posted 2006-10-31 03:46
高级用户 Posts 247 Credits 846 From 湖南==》广东
rem Read the ping command return result using for;
for /f "delims=" %%i in ('ping www.21cn.com') do (

rem Initialize ret (here it means clearing);
set ret=

rem "if defined %%a" is to check whether the corresponding variable %%a exists, and if it exists, replace it with the variable value; (the variable is the word we want to translate, and the variable value has been set to the corresponding Chinese meaning)
for %%a in (%%i) do if defined %%a (set ret=!ret!!%%a!) else set ret=!ret! %%a

rem Because the time is not easy to translate here, so directly adopt this alternative method.
if not "!ret!"=="" (set ret=!ret:time=时间! && echo !ret!) else echo.
)
Floor17 yangzhiyi Posted 2006-10-31 06:27
中级用户 Posts 123 Credits 261
These two sentences are still not understood. Can you explain again?
if defined %%a (set ret=!ret!!%%a!) else set ret=!ret! %%a
if not "!ret!"=="" (set ret=!ret:time=时间! && echo !ret!) else echo.
Can it be replaced in the whole section? For example
set Request timed out.=Response request timed out.
set TTL Expired in Transit=The number of required hops exceeded the "Time to Live" (TTL)
set Approximate round trip times in milli-seconds:=Approximate round trip times in milliseconds:=
This seems to work in the command line, but it doesn't seem to work in this batch processing. Is the variable name with spaces not okay? Can the variable value have spaces? If it can, can we first set a variable to be in English? For example
set imedout=Request timed out.
set imedout=Response request timed out.
Because I haven't understood it yet, I can't test it by myself. Please take a look again.

[ Last edited by yangzhiyi on 2006-11-1 at 01:56 AM ]
Prev  1 2
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023