Windows批处理文件:如果其他人 [英] Windows Batch Files: if else

查看:123
本文介绍了Windows批处理文件:如果其他人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我这样做,需要一个参数一个简单的批处理文件(可以提供更多的,但我忽略它们)。

有关测试,这是我到目前为止所。

 如果没有%1 ==(
    目录/ S / B%1
)其他(
    没有回音

基本上,我想说如果提供一个参数,递归显示文件夹中的所有文件。否则,说没有。

它工作时,我提供了一个说法,但如果我不提供对一个,它会告诉我(在这个时候意外

我的意思是,它的工作原理,但我想至少显示一个用户友好的消息,解释为什么它不工作。我应该如何改变code?


解决方案

 如果没有%1 ==(

必须

 如果不是%1==(

如果参数没有给出,它是完全空的,甚至不是(其中重presents大多数编程语言空字符串)。所以我们用引号周围检测到空的参数。

I'm doing a simple batch file that requires one argument (you can provide more, but I ignore them).

For testing, this is what I have so far.

if not %1 == "" (
    dir /s/b %1
) else (
    echo no
)

Basically, I want to say if an argument is provided, recursively display all the files in the folder. Otherwise, say no.

It works when I provide an argument, but if I don't provide one it'll just tell me ( was unexpected at this time.

I mean, it works, but I wanted to at least display a user-friendly message explaining why it doesn't work. How should I change the code?

解决方案

if not %1 == "" (

must be

if not "%1" == "" (

If an argument isn't given, it's completely empty, not even "" (which represents an empty string in most programming languages). So we use the surrounding quotes to detect an empty argument.

这篇关于Windows批处理文件:如果其他人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆