中国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-08-02 06:01
48,037 topics / 350,122 posts / today 2 new / 48,250 members
DOS批处理 & 脚本技术(批处理室) » [Closed] IF, ELSE
Printable Version  3,019 / 10
Floor1 uemuem Posted 2006-10-14 00:53
初级用户 Posts 68 Credits 153 From 上海
I'm a new arrival, please take care, hehe, just groping...

@echo off
fc 1.txt 2.txt>3.txt
setlocal enabledelayedexpansion
for /f %%a in (3.txt) do set file1=%%a !file1!
if %file%==""
(
goto end
)
else
(
copy test.xls e:\备份.xls
)
:end

[ Last edited by uemuem on 2006-10-14 at 01:17 ]
Floor2 vkill Posted 2006-10-14 01:02
金牌会员 Posts 1,744 Credits 4,103 From 甘肃.临泽
for /f "tokens=*" %%a in (3.txt) do copy %%a e:\备份.xls

Is this enough? Why make it so complicated?
Floor3 ARCF Posted 2006-10-14 01:05
初级用户 Posts 14 Credits 32
Does batch processing have if else? I think this one looks like the language of PASAL
Floor4 namejm Posted 2006-10-14 01:14
荣誉版主 Posts 1,737 Credits 5,226 From 成都
if %file%=="" is a syntax format error. The correct one should be if ""%file%""=="" Pay attention to adding quotes.
Floor5 uemuem Posted 2006-10-14 01:22
初级用户 Posts 68 Credits 153 From 上海
Floor6 weilong888 Posted 2006-10-14 01:47
银牌会员 Posts 548 Credits 1,270
If the IF command is mastered correctly, it can be very useful.
Floor7 uemuem Posted 2006-10-14 01:48
初级用户 Posts 68 Credits 153 From 上海
Actually, I still don't quite understand. Can you explain it in more detail?

I still get a syntax error like this:

@echo off
setlocal enabledelayedexpansion
for /f %%a in (1.txt) do set file1=%%a !file1!
for /f %%a in (2.txt) do set file2=%%a !file2!
if "%file1%"=="%file2%"(
goto end
)else(
copy test.xls e:\备份.xls
)
:end
Floor8 namejm Posted 2006-10-14 06:14
荣誉版主 Posts 1,737 Credits 5,226 From 成都
If there is still a syntax error, there are probably two places where the problem occurs:

1. The format of the else part is incorrect. The correct format should be if condition (command1) else (command2). In the top floor, the else is not on the same line as the if; in the 7th floor, the parentheses are connected with else; there is also a problem of writing parentheses and statements together in if "%file1%"=="%file2%"(;
2. The sentence if "%file1%"=="%file2%" may also have a problem. Because the content extracted by your %file1% and %file2% are both the content in the file. If there are sensitive characters under CMD in the file content, this sentence will have an error.
Floor9 uemuem Posted 2006-10-16 22:07
初级用户 Posts 68 Credits 153 From 上海
Floor10 不得不爱 Posted 2006-10-16 22:29
超级版主 Posts 2,044 Credits 5,310 From 四川南充
Originally posted by namejm at 2006-10-14 01:14:
  if %file%=="" is a syntax format error. The correct one should be if ""%file%"=="" . Please note to add quotes.

if %file%=="" is not a syntax format error. If the value of variable file is "", the condition is established.
The mistake is (not adding












Last edited by qwe1234567 on 2006-10-16 at 22:37 ]
Floor11 lxmxn Posted 2006-10-17 04:48
版主 Posts 4,938 Credits 11,386

What the above moderator said is extremely true.

A space is an effective default separator between commands, between commands and various symbols, and between commands and parameters. If you omit the space, cmd.exe will think that the written-together content is a single statement or command, and then cmd.exe cannot interpret or execute it, thus an error will occur. Therefore, when writing batch scripts or commands in the command line, you must pay attention to the writing norms. Especially novice friends (of course, I am also one ~: ) ) should pay attention to this point.
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023