检查驱动器号是否批量存在,否则转到另一段代码

我试图做一个代码,检测是否存在一个驱动器号。

例如,要检查C:驱动器是否存在,我的代码是:

@echo off title If Exist Test :main CLS echo. echo press any key to see if drive C: exists echo. pause>nul IF EXIST C: GOTO yes ELSE GOTO no :yes cls echo yes pause>nul exit :no cls pause>nul exit

但它不起作用,它要么:是的,如果C:存在或鞋子如果没有空白的屏幕。 我做错了什么,所以它不会去:不是吗?

有没有办法只redirectstderr标准输出(不结合这两个),所以它可以pipe道到其他程序?

pipe道输出时如何在batch file中显示消息?

获取启动分区驱动器名称

批量查找文件扩展名

如何使用命令输出作为另一个命令的参数?

批量文件更改

使用batch file删除具有条件的特定文件

将Stringreplace为多个文件

如何在Windows中随时捕获命令提示符的显示输出

如何用.bat脚本closures窗口?

@echo off title If Exist Test :main CLS echo. echo press any key to see if drive C: exists echo. pause>nul ::NB: you need the brackets around the statement so that the file ::kNows that the GOTO is the only statement to run if the statement ::evaluates to true,and the ELSE is separate to that. IF EXIST C: (GOTO yes) ELSE (GOTO no) ::I added this to help you see where the code just runs on to the ::next line instead of obeying your goto statements echo no man's land :yes ::cls echo yes pause>nul exit :no ::cls echo no pause>nul exit

你的代码中的主要问题是if ... else语法。 完整的命令需要被读取/解析为一个单独的代码块。 这并不意味着它应该写在一行,但如果不是,行必须包括信息给解析器,所以它知道命令继续在下一行

if exist c: ( echo exists ) else ( echo does not exist) ---- if exist c: ( echo exists ) else echo does not exist ---- if exist c: ( echo exists ) else echo does not exist ---- if exist c: ( echo exists ) else ( echo does not exist )

任何以前的代码将按预期工作。

无论如何,检查驱动器的根文件夹将生成一些类型的驱动器弹出(在我的情况下,它是多卡读卡器)。 为了避免它,请使用vol命令并检查错误级别

vol w: >nul 2>nul if errorlevel 1 ( echo IT EXISTS ) else ( echo IT DOES NOT EXIST )

经验证可以在Win7下工作。 尝试使用您选择的(现有和不存在的)驱动器盘符:

@IF EXIST O: (GOTO cont1) @ECHO not existing @GOTO end :cont1 @ECHO existing! :end

相关文章

本篇内容主要讲解“gitee如何上传代码”,感兴趣的朋友不妨来...
这篇“从gitee上下的代码如何用”文章的知识点大部分人都不太...
这篇文章主要介绍“gitee如何下载仓库里的项目”,在日常操作...
本篇内容主要讲解“怎么在Gitee上更新代码”,感兴趣的朋友不...
本文小编为大家详细介绍“怎么将工程托管到gitee”,内容详细...
这篇文章主要介绍了gitee中图片大小如何调整的相关知识,内容...