@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET "sourcedir=c:\sourcedir"
SET "destdir=c:\destdir"
FOR /r "%sourcedir%" %%a IN (*.jpg) DO (
SET "newname=%%a"
SET "newname=!newname:*%sourcedir%\=!"
ECHO COPY /b "%%a" "%destdir%\!newname:\=_!"
)
GOTO :EOF
Grab each filename, remove the source directory name and a \
, then copy the file to that name, changing each \
to _
.
The required commands are merely ECHO
ed for testing purposes. After you've verified that the commands are correct, change ECHO COPY
to COPY
to actually copy the files.
Edit : fixed to allow spaces in sourcedir
(simply quote after the /r
in the for
)