Built on Sin
Built on Sin

Reputation: 351

Simple wildcard use

EDIT: I have just changed the if to an if else

IF "%CD:~1%"==":\" ( set FIR=%CD:~0,2% ) ELSE ( set FIR=%CD% )

Trying to use a wildcard to detect if a batch file is on the root directory (As root causes there to be a backslash at the end of the DIR)

I need to determine with a simple if statement whether it is *:\ or not. I have tried using wildcards *:\ and ?:\ but to no avail. If I use the drive letter, example: G:\ it works.

if %CD%==G:\ echo SOMETHING WRONG HERE

works perfectly well, until the drive letter changes. Where as

if %CD%==?:\ echo SOMETHING WRONG HERE

or

if "%CD%"=="?:\" echo SOMETHING WRONG HERE

Doesn't work.

EDIT: After reading up it turns out if and wildcards are not compatible!

Upvotes: 0

Views: 162

Answers (2)

Endoro
Endoro

Reputation: 37569

try this:

if "%CD:~-2%"==":\" (echo root) else echo NOT root

see docu help set.

Upvotes: 2

Built on Sin
Built on Sin

Reputation: 351

Wildcards are not usable within IF statements in command.

Upvotes: 0

Related Questions