DPeterK
DPeterK

Reputation: 408

Getting error "The filename, directory name, or volume label syntax is incorrect." from a batch script

I have a batch script that conditionally sets a variable based on another variable:

set LABEL_NAME=main
echo %LABEL_NAME%
set UPLOAD_CHANNELS= 

/E:ON /V:ON if not defined %BINSTAR_TOKEN% set UPLOAD_CHANNELS=--upload-channels scitools/label/!LABEL_NAME!

echo %UPLOAD_CHANNELS%

I get the error:

The filename, directory name, or volume label syntax is incorrect.

from the line containing the inline if statement.

Note that the variable UPLOAD_CHANNELS is first defined to equal a single space character.

Upvotes: 1

Views: 3480

Answers (1)

elzooilogico
elzooilogico

Reputation: 1705

does your code look like something like this?

@echo off

setlocal enableextensions enabledelayedexpansion

set "LABEL_NAME=main"
echo %LABEL_NAME%
set "UPLOAD_CHANNELS= "

if not defined BINSTAR_TOKEN set "UPLOAD_CHANNELS=--upload-channels scitools/label/!LABEL_NAME!"

echo %UPLOAD_CHANNELS%

Note that using the defined keyword look for variable name not for its content, so no need %

I guess your code does something more, at this point there is no need for delayed expansion

Upvotes: 1

Related Questions