|
uemuem
初级用户
 
积分 153
发帖 68
注册 2006-10-12 来自 上海
状态 离线
|
『楼 主』:
[已结]IF、ELSE
使用 LLM 解释/回答一下
我是新进门的,关照一下,呵呵,正在摸索中。。。
@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 ]
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 ]
|

个人主页-找餐厅:http://www.canting.cc |
|
2006-10-14 00:53 |
|
|
vkill
金牌会员
     
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
for /f "tokens=*" %%a in (3.txt) do copy %%a e:\备份.xls
这样就可以了,搞那么复杂?
for /f "tokens=*" %%a in (3.txt) do copy %%a e:\备份.xls
Is this enough? Why make it so complicated?
|
|
2006-10-14 01:02 |
|
|
ARCF
初级用户
 
积分 32
发帖 14
注册 2006-10-9
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
批处理有if else吗?我瞅着这条像是PASAL的语言啊
Does batch processing have if else? I think this one looks like the language of PASAL
|
|
2006-10-14 01:05 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
if %file%=="" 属于语法格式错误,正确的应该是 if "%file%"=="" ,请注意加引号。
if %file%=="" is a syntax format error. The correct one should be if ""%file%""=="" Pay attention to adding quotes.
|

尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2006-10-14 01:14 |
|
|
uemuem
初级用户
 
积分 153
发帖 68
注册 2006-10-12 来自 上海
状态 离线
|
|
2006-10-14 01:22 |
|
|
weilong888
银牌会员
    
积分 1270
发帖 548
注册 2004-5-31
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
if命令掌握正确了,可大有用处。
If the IF command is mastered correctly, it can be very useful.
|
|
2006-10-14 01:47 |
|
|
uemuem
初级用户
 
积分 153
发帖 68
注册 2006-10-12 来自 上海
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
其实我还是没太明白,能说详细点吗?
我这样还是提示语法错误:
@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
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
|

个人主页-找餐厅:http://www.canting.cc |
|
2006-10-14 01:48 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
如果还提示语法错误的话,估计有两个地方会出问题:
1、else部分格式不对,正确的格式应该是 if 条件 (command1) else (command2),你在顶楼的 else 与 if 不在同一行上;第7楼的又把括号和 else 连在一起了;if "%file1%"=="%file2%"( 也存在括号与语句连写的问题;
2、if "%file1%"=="%file2%" 这一句也可能有问题。因为你的%file1% 和 %file2% 提取的都是文件里的内容,如果文件内容中含有CMD下的敏感字符的话,这条语句就会发生错误。
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.
|

尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2006-10-14 06:14 |
|
|
uemuem
初级用户
 
积分 153
发帖 68
注册 2006-10-12 来自 上海
状态 离线
|
|
2006-10-16 22:07 |
|
|
不得不爱
超级版主
         我爱DOS
积分 5310
发帖 2044
注册 2005-9-26 来自 四川南充
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
Originally posted by namejm at 2006-10-14 01:14:
if %file%=="" 属于语法格式错误,正确的应该是 if "%file%"=="" ,请注意加引号。
if %file%=="" 不属于语法格式错误,如果变量file的值就是""的话条件就成立。
错误的是(没有加在if %file%==""的后面。
另外7楼少打了几个空格
@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
Last edited by qwe1234567 on 2006-10-16 at 22:37 ]
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 ]
|

我的网络U盘 我的网络第2个U盘
论坛软件下载链接
灵雨飘零论坛
论坛新手必读,所有人的基本行为准则
刷QQ空间人气、留言的小软件 |
|
2006-10-16 22:29 |
|
|
lxmxn
版主
       
积分 11386
发帖 4938
注册 2006-7-23
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
楼上版主所言极是。
空格是命令与命令,命令与各种符号以及命令和参数之间有效的默认分隔符,如果把空格省略了,cmd.exe就会以为写在一起的是一条语句或者命令,这样cmd.exe就解释不了,也就执行不了,因而会报错,所以在写批处理或者在命令行下写命令的时候,一定要注意书写的规范。特别是新手朋友(当然我也是啦~: ) )要注意这点。
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.
|
|
2006-10-17 04:48 |
|