Search code examples
windowsbatch-file

how can I copy files from all subdirectory according to a specific file type


I have a Makefile that has a bash command that I need to convert to a Windows batch file.

The command is:

find "source" -type f -wholename '*/.bin/output/*.dll' -exec cp\{\} "./dest" \;

The idea of this command is to copy all DLL files in /.bin/output/ folders and copy them to the dest folder.

To my knowledge, there is no equivalent command for find.

Can someone help me with that?


Solution

  • I finally succeeded in solving this.

    @echo off
     
    set "sourceDir=%cd%"
    set "destDir=%cd%\build"
    set fileCount=0
     
    if not exist "%destDir%" (
        mkdir "%destDir%"
    )
     
    for /r "%sourceDir%" %%d in (.bin) do (
        if exist "%%d\output" (
            for %%f in ("%%d\output\*.dll") do (
                copy "%%f" "%destDir%" >nul
                if not errorlevel 1 (
                    set /a fileCount+=1
                )
            )
        )
    )
    

    This works as expected. Thanks to everyone who commented on this post.