This should work for you:
@echo off
set "dir=C:\Your\Root\Folder"
set "tem=%dir%\!!_Temp"
for /d %%A in (*) do (
for %%B in (%%A\*_0001.png) do (
if not exist "%tem%\%%~nxB" copy /y "%%B" "%tem%\"
)
)
To make things cleaner and easier to change, we set two variables - one for your root folder (dir
) and one for the !!_Temp
folder (tem
) inside your root; this also assumes based on your question that you're running the .bat file from the root folder - if this isn't the case we can edit the path in the first for-loop.
The first loop has for /d
which looks only at top-level folders in your current directory, and for each iteration of the loop those top-level folders are set as parameter %%A
. The next loop looks only at files matching the criteria we set - which is anything in %%A
that ends in _0001.png
- and sets each of those as parameter %%B
. The command in this final loop is if not exist "%tem%\%%~nxB" copy /y "%%B" "%tem%\"
- we include the if not exist
so it doesn't run on files that have already been copied to !!_Temp
. Based on your question I'm not sure if you'd ever run into multiple files in multiple subfolders that have the exact same name, but if that is a potential case we can work around that.