Baur
Baur

Reputation: 111

Issue with a variable in my batch script

I want my script to:

What is wrong with the following code? The ECHO statement just prints Your directory is set to; the DIR statement works as expected.

@ECHO OFF
SET custompath = "C:\Users\%1"
ECHO  Your directory is set to %custompath%
DIR %custompath%

Upvotes: 0

Views: 306

Answers (2)

djangofan
djangofan

Reputation: 29669

Personally, I would do it this way:

@ECHO OFF
SET /P "custompath=Enter a custom windows path: "
ECHO Showing contents of directory ^"%custompath%^"
DIR /b "%custompath%"
pause

Upvotes: 0

MrCleanX
MrCleanX

Reputation: 416

It's the space around the =.

@ECHO OFF
SET custompath="C:\Users\%1"
ECHO  Your directory is set to %custompath%
DIR %custompath%

Check this post.

Upvotes: 2

Related Questions