Like Helbreder pointed out, there is a space after set file=%f:~0,-4%
.
To avoid this type of problems you can use the extended syntax of SET
.
set "file=%f:~0,-4%"
The surrounding quotes will ensure that only all characters until the last quote are part of the string.
The quotes itself are not part of the string.
So even this would work
set "file=%f:~0,-4%" the spaces and this text will be removed
Another positive effect from the quotes is that they will avoid problems with special characters in the filename, like in Cat&Dog
.
So your code should look like
@echo off
for /F "tokens=*" %%A in (events.txt) do call :makemove %%A
pause
exit
:makemove
set "f=%~1"
set "file=%f:~0,-4%"
md "X%file%"
set "dest=C:\Users\sony\Desktop\X%file%"
move /y "C:\Users\sony\Desktop\*%file%*.*" "%dest%"