如果从驱动器运行,则停止批处理文件 [英] Stop Batch file if its being run from a drive

查看:44
本文介绍了如果从驱动器运行,则停止批处理文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,如果要从特定驱动器运行批处理文件,我想停止它.我已经尝试过类似的操作,但是它不起作用.如果有人有更好的主意,我将不胜感激.

Hi I want to stop a batch file if it is being run from a particular drive. I have tried somehting like this, it doesn't work though. I would appreciate it if someone has a better idea.

if %CD%=="^.*C:\" (goto :CDrive)

:CDrive是错误消息,表明用户正尝试从错误的驱动器运行它.

Where :CDrive is an error message saying that the user is trying to run it from the wrong drive.

欢呼克里斯

推荐答案

您可以使用子字符串进行检查:

You can use a substring to check:

if "%CD:~0,2%"=="C:" goto CDrive

另一种选择可能是您只是明确设置了所需的驱动器:

Another option might be that you just explicitly set the drive you're expecting:

pushd X:

或使用完整路径,而不是相对路径.

or use full paths instead of relative ones.

这篇关于如果从驱动器运行,则停止批处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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