Batch file to get all images in a directory and copy them

Here is how to search a directory and sub directories to find all images and then copy them to another directory using a simple batch file.

Looping through the directory and using Xcopy /Y which copies and overwrites the simple command get the job done.

Save the following code as a .bat file making sure you edit the folder to search and where to save the found images to.

pushd C:\dir\dir2\
for /r %%a in (*.jpg;*.png) do (
   XCOPY /Y "%%a" "C:\allimg"
)
popd