1

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)

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

Cheers Chris

Chris
  • 317
  • 3
  • 7
  • 12
  • I'm not even sure why you would expect that to work. At the very least the backslash at the end would make for an invalid regex. Not to mention that `cmd` doesn't support regular expressions anywhere. – Joey Jul 20 '12 at 12:55

1 Answers1

2

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.

Joey
  • 344,408
  • 85
  • 689
  • 683