%~1 tries to parse a list of arguments
and will give you:
%~s1 will fail too.
gulp the entire thing,
and re-parse content into short-path for easier usage.
@echo off :: enable Unicode support for path/file-name. chcp 65001 2>nul >nul :: single arg - workaround weird file-name. set "ARG=%*" for /f %%a in ("%ARG%") do ( set 'ARG=%%~fsa' )
the code above will generate a fully-qualified,
short (8.3-DOS like) path.
if you do need to pass more than one argument,
this is not the solution for you.
– – – – – –
The above code does not always works
since it will turn off any tries to parse single argument from the string,
%* to other programs as an argument will always work,
but built-in handling of file-names, with apostrophes will still fail,
due to “by design” issues in CMD (wrapping phrases uses apostrophes..)
instead, try passing
GetShortPathName.exe from github.com/eladkarako/GetShortPathName,
with the additional processing allowing empty-strings/empty-character (
\0) and Windows API.
it will return a short 8.3 version of the path (relative or full),
if you want a fully qualified path try using
GetFullPathName.exe from github.com/eladkarako/GetFullPathName.
You can use your choice of implementations, that simple one is written in VB6.