0

I want my script to:

  • Accept a variable
  • Create a path using that variable as input
  • Display the path
  • Display the contents of the directory

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%
Baur
  • 111
  • 1

2 Answers2

2

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.

Community
  • 1
  • 1
MrCleanX
  • 416
  • 2
  • 13
0

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
djangofan
  • 28,471
  • 61
  • 196
  • 289