0

I am unable to figure out why the value is not stored in a variable in Windows 10. I search on the internet didn't get any reason why this not working.

@echo off
:start
REM check if there are more then one argumnets
if not "%2" == "" (
echo Too many parameters entered 
) ELSE (
REM check if argument one is empty
SETLOCAL ENABLEDELAYEDEXPANSION
if "%1"=="" (
echo "Enter your Name"
SET /P filename=
echo Your Name  is "%filename %" 
) 
if "%filename%"=="" (
echo "empty"
) else (
 echo "dat"
)
) 

When I run this:

Enter your Name
asd
Your Name  is

Am I doing something wrong?

James Z
  • 12,209
  • 10
  • 24
  • 44
Arslan Ahmad khan
  • 5,426
  • 1
  • 27
  • 33
  • Possible duplicate of [How do SETLOCAL and ENABLEDELAYEDEXPANSION work?](https://stackoverflow.com/questions/6679907/how-do-setlocal-and-enabledelayedexpansion-work). In addition the issue first mentioned in the comments is covered, [here](https://stackoverflow.com/q/10552812). As a side note, please don't expect our members to visit a web site to download a file and open it to read a small piece of code, you could have very quickly copied and pasted into your question. I have now edited your question to include the content of that file, please delete previous your comment above. – Compo Apr 20 '19 at 17:00
  • `"%filename %"` has to be `"%filename%"` (in fact, `"!filename!"`) – Stephan Apr 20 '19 at 18:15

1 Answers1

2

This may also help you out:

@Echo Off
SetLocal EnableDelayedExpansion
If "%~1"=="" (
    Echo No parameter was passed
    GoTo EndIt
) Else (
    If Not "%~2" == "" (
        Echo Too many parameters entered 
        GoTo EndIt
    ) Else (
        Echo "Enter your Name"
        Set /P "filename="
        If "!filename!"=="" (
            Echo "empty"
        ) Else (
            Echo Your Name  is "!filename!"
            Echo "dat"
        )
    )
)
:EndIt
Pause
GoTo :EOF
Compo
  • 36,585
  • 5
  • 27
  • 39