4

Trying to print out the 8dot3 name of a file, it does works when I paste the line in the Command Prompt but not when I run it from a batch file.

Result when pasted :

D:\tmp>cmd /e:on /c for %A in (8088_othello.com) do @echo %~nxsA

8088_O~1.COM

Result from batch file :

D:\tmp>lfn.bat

D:\tmp>cmd /e:on /c for ~nxsA

~nxsA was unexpected at this time.

What else is needed to make it work inside a batch file ?

1
  • My issue was encoding. When I made bat file to be utf-8 things worked. Previously it was on ucs-2 Commented Jul 5, 2017 at 11:38

1 Answer 1

8

you need to escape % is batch files

just type cmd /e:on /c for %%A in (8088_othello.com) do @echo %%~nxsA

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

3 Comments

ss64.com/nt/syntax-esc.html - its for both for loops and passing it to other applications as well
Good solution. Fixed my problem instantly. I always thought .bat= direct cmd script
I just double the %% as said and it works, thank you

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.