Assuming spaces are consistent with your example (i.e. Firstname and Lastname don't have spaces), this should work.
for /f "tokens=1,2,*" %%a in ('dir /a:d /b') do (
ren "%%a %%b %%c" "%%b !lastname!"
It just splits by spaces, and trims the comma off the Lastname, of all directories in the same directory as the batch file.
If the names can have spaces, some delimiter manipulation is necessary. I'll go fiddle with that.
Here we go. Fiddling with delimiters means Firstname was surrounded by a space before and after it, which had to be trimmed out. So essentially, it expects a
Lastname followed by a
, followed by a
followed by a
(whatever. The spaces around Firstname are important (and are there in your example). Spaces within the names work fine.
for /f "tokens=1,2,* delims=,(" %%a in ('dir /a:d /b') do (
ren "%%a,%%b(%%c" "!firstname! %%a"
You may wish to have a test run, by putting an
echo before the
ren, to make sure it works as expected.