I have a file named 01_tiago_miguel.txt
and this code:
setlocal EnableExtensions DisableDelayedExpansion
for %%A in ("*_*") do (
rem // Store current item:
set "FILE=%%~A"
rem // Toggle delayed expansion to avoid loss of or trouble with `!`:
setlocal EnableDelayedExpansion
rem // Remove everything up to and including the first `_`:
echo ren "!FILE!" "!FILE:*_=!"
)
endlocal
exit /B
This gives the output:
ren "01_tiago_miguel.txt" "tiago_miguel.txt"
Which is exactly what I want - remove the first three characters.
However if I remove the echo
it renames to miguel.txt
, which doesn't make much sense since the output of the echo seems correct.
Any idea why?