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%

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

echo DIR %custompath% --> DIR echo DIR %custompath % --> DIR "C:\Users\"
Works fine, as long as the path exists ;)
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.