As already commented, you can't simply use ren
with wildcards here.
Therefore you have to process each file on its own. cmd
provides the for
loop to do so:
for %%a in (*-*) do call :removedash "%%a"
goto :eof
:removedash
set "name=%~n1" &REM take name only
set "name=%name:-=%" &REM remove dashes
set "name=%name: = %" &REM replace double-spaces with single-space
ECHO ren "%~1" "%name%%~x1"
Note: if you have a space both before and after the dash, removing the dash results in two consecutive spaces, which you probably don't want, so we replace them with a single space. We could just replace <space><dash><space>
with <space>
, but I'm not sure if we can trust there are spaces around the dash.
NOTE: I "disarmed" the ren
command for security reasons. Remove the ECHO
when you are sure it does what you want.