系统找不到指定的驱动器

系统找不到指定的驱动器

本文介绍了意外的“系统找不到指定的驱动器".在批处理文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

批处理文件(Windows 7 x64)出现问题.我设法将其简化为以下内容(有两个空的注释行;是否有实际的注释似乎无关紧要):

I've got a problem with a batch file (Windows 7 x64). I've managed to reduce it to the following (there are two empty comment lines; it doesn't seem to matter whether there's an actual comment):

@echo off

if /i [%1]==[] (
    echo A
    ::
    ::
    echo B
)

将其放入批处理文件中,然后在不使用任何参数的情况下运行,将产生以下输出:

Putting this in a batch file and then running it with no parameters produces the following output:

A
The system cannot find the drive specified.
B

删除::行之一,或删除周围的if修复东西,以便获得预期的输出:

Deleting one of the :: lines, or deleting the surrounding if, fixes things so you get the expected output:

A
B

这是怎么回事?为什么要寻找驱动器?

What's going on here? Why is it looking for a drive?

修改

非常感谢您的回覆.所以我的问题真的可以归结为:

Thanks for the responses for far. So my question really boils down to this:

也许切换回REM来添加注释会更容易,所以没有歧义的范围,但是我确实发现::样式更易于阅读.

Perhaps it's easier to just switch back to REM for adding comments so there's no scope for ambiguity, but I do find the :: style easier to read.

推荐答案

这在批处理代码块中是一种晦涩的效果.

It's an obscoure effect in batch code blocks.

在代码块中,一行中的标签始终需要具有完全不同的语法规则的第二行(对于 secondary 行).
SO:goto命令不起作用

In a code block a label in one line requires always a secondary line with quite different syntax rules (for a secondary line).
SO: goto command not working

辅助行必须是命令或简单标签,但不能是括号,双冒号或带有括号的内部命令.

The secondary line must be a command or simple label, but not a parenthesis nor a double colon nor an internal command appended with a parenthesis.

MC ND解释说:在这里像普通的驱动器号一样使用,的确如此!
但是仅在第二行中,即使您可以通过subst :: C:\抑制错误,该行也像标签一样被处理(您不能启动任何内容).

MC ND explained that the : is used here like a normal drive letter, that's really true!
But only in the secondary line and even you can suppress the error by a subst :: C:\, the line is handled like a label (You can't start anything).

subst :: C:\
(
:label
::\windows\system32\calc.exe
)

并且第二行接受&,即使该行是标签.

And the secondary line accepts & even when the line is a label.

样品失败

(
:Label at the end fails
)

(
:label
  (
    echo new Block fails
  )
echo ...
)

(
:label
:: Double colon fails
)

(
:label
echo( fails also, as now a file named "echo(" is searched for execution
)

现在正在工作的人

(
::Works
:with a "normal" label in the second line
)

(
:But this label! & echo This will not echo'd
:but & echo You can see this !
)

(
:label
echo or a simple command works too
)

有时::用作注释样式,如果您不这样做,可能会在块内引起问题关心辅助线.

Sometimes :: is used as a comment style, this can cause problems inside blocks, if you don't care about the secondary line.

要回答第二个问题

第一个::始终是注释或标签,在下一行中始终是drive letter colon.

The first :: is always a comment or label, in the next line it's always a drive letter colon.

这篇关于意外的“系统找不到指定的驱动器".在批处理文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 01:55