Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Command works in Command Prompt but not in a batch file

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 ?

like image 292
aybe Avatar asked Feb 16 '23 14:02

aybe


1 Answers

you need to escape % is batch files

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

like image 58
Mehul Rathod Avatar answered Feb 23 '23 20:02

Mehul Rathod