Based on the OP it sounds like you only want a copy of the singular 'build.a' file in the name of the 'Build_...' directory name, within a sibling top-level 'Result' directory.
In which case the following works. Simply have the parent directory as the input of the script (eg: by dragging the directory that contains 'Build', etc sub-directories onto the script). The 'sourcenamecheck', 'filename' and 'destname' variables can be changed in the script if your actual file/dir names differ from your examples.
If there are additional 'Build_...' directories it will create a separate sub-directory in Results named after each one.
Code: Select all
:: Assumes input directory is parent directory of 'Build_...', etc directories
@echo off
setlocal enableextensions enabledelayedexpansion
set "sourcenamecheck=Build_"
set "filename=build.a"
set "destname=Result"
set "input=%1"
:: Remove double quotes
set "input=!input:"=!"
echo [Script] Input path: !input!
:: Not using recursive (/r) option since only wanting to check top-level directories
for /d %%b in ("!input!\!sourcenamecheck!*") do (
set "source=%%b"
set "sourcename=%%~nxb"
if exist "!source!\!filename!" (
rem Creates destination directories if they don't exist
if not exist "!input!\!destname!" md "!input!\!destname!"
if not exist "!input!\!destname!\!sourcename!" md "!input!\!destname!\!sourcename!"
echo [Script] Found "!filename!" file. Copying to "!destname!"...
copy "!source!\!filename!" "!input!\!destname!\!sourcename!\!filename!"
if !errorlevel! neq 0 (
echo [Script] Error encountered. Exit code: !errorlevel!.
) else (
echo [Script] Complete.
)
) else (
echo [Script] "!filename!" file not found.
)
)
pause >nul|set /p "=[Script] Press any key to exit... " & exit
exit /b
This will produce, eg:
Result\Build_5.5\build.a
Where 'Result' is beside the original 'Build_5.5' directory (or whatever number it is).