Skip to content

Commit b17b254

Browse files
authored
Merge pull request #364 from pmienk/scoped-copy
Add output copy scoping.
2 parents 1c3a386 + 675fbd8 commit b17b254

File tree

4 files changed

+98
-6
lines changed

4 files changed

+98
-6
lines changed

copy_projects.cmd

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
@echo off
2+
setlocal EnableDelayedExpansion
3+
4+
:: Assign arguments
5+
set "source_dir=output"
6+
set "dest_dir=.."
7+
8+
:: Check if source directory exists
9+
if not exist "%source_dir%\" (
10+
echo Error: Source directory "%source_dir%" does not exist.
11+
exit /b 1
12+
)
13+
14+
:: Create destination directory if it doesn't exist
15+
if not exist "%dest_dir%\" (
16+
echo Error: Destination directory "%dest_dir%" does not exits.
17+
exit /b 1
18+
)
19+
20+
:: If no substring arguments are provided, copy all subdirectories
21+
if "%~1"=="" (
22+
echo No substrings specified. Copying all subdirectories from "%source_dir%" to "%dest_dir%"...
23+
for /d %%i in ("%source_dir%\*") do (
24+
set "subdir=%%~nxi"
25+
echo Copying '!subdir!' to '%dest_dir%'...
26+
xcopy "%%i" "%dest_dir%\!subdir!\" /E /I /Y
27+
)
28+
) else (
29+
:: Copy subdirectories whose names contain any of the provided substrings
30+
set copied=0
31+
for /d %%i in ("%source_dir%\*") do (
32+
set "subdir=%%~nxi"
33+
set found=0
34+
for %%j in (%*) do (
35+
echo.!subdir! | find /i "%%j" >nul
36+
if !errorlevel! equ 0 (
37+
echo Copying '!subdir!' to '%dest_dir%'...
38+
xcopy "%%i" "%dest_dir%\!subdir!\" /E /I /Y
39+
set found=1
40+
set /a copied+=1
41+
)
42+
)
43+
)
44+
if !copied! equ 0 (
45+
echo Warning: No subdirectories found in "%source_dir%" matching any provided substrings.
46+
)
47+
)
48+
49+
echo Copy operation completed.
50+
endlocal

copy_projects.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/bash
2+
# Assign arguments
3+
source_dir="output"
4+
dest_dir=".."
5+
6+
# Check if source directory exists
7+
if [ ! -d "$source_dir" ]; then
8+
echo "Error: Source directory '$source_dir' does not exist."
9+
exit 1
10+
fi
11+
12+
# Create destination directory if it doesn't exist
13+
mkdir -p "$dest_dir"
14+
15+
# If no subdirectory arguments are provided, copy all subdirectories
16+
if [ "$#" -eq 0 ]; then
17+
echo "No substrings specified. Copying all subdirectories from '$source_dir' to '$dest_dir'..."
18+
for subdir in "$source_dir"/*/ ; do
19+
if [ -d "$subdir" ]; then
20+
subdir_name=$(basename "$subdir")
21+
echo "Copying '$subdir_name' to '$dest_dir'..."
22+
cp -r "$subdir" "$dest_dir/"
23+
fi
24+
done
25+
else
26+
# Copy subdirectories whose names contain any of the provided substrings
27+
copied=0
28+
for subdir in "$source_dir"/*/ ; do
29+
if [ -d "$subdir" ]; then
30+
subdir_name=$(basename "$subdir")
31+
for substring in "$@"; do
32+
if [[ "$subdir_name" == *"$substring"* ]]; then
33+
echo "Copying '$subdir_name' to '$dest_dir'..."
34+
cp -r "$subdir" "$dest_dir/"
35+
copied=$((copied + 1))
36+
break
37+
fi
38+
done
39+
fi
40+
done
41+
if [ "$copied" -eq 0 ]; then
42+
echo "Warning: No subdirectories found in '$source_dir' matching any provided substrings."
43+
fi
44+
fi
45+
46+
echo "Copy operation completed."

generate4.cmd

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ REM Execute property copiers and artifact generators.
3232
call copy_modules.cmd
3333
call copy_properties.cmd
3434
call generate_artifacts.cmd
35-
36-
REM Copy outputs to all repositories.
37-
xcopy /s /y output\* ..\
35+
call copy_projects.cmd %*
3836

3937
REM Restore directory.
4038
popd

generate4.sh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,4 @@ eval chmod +x generate_artifacts.sh
3737
eval ./copy_modules.sh
3838
eval ./copy_properties.sh
3939
eval ./generate_artifacts.sh
40-
41-
# Copy outputs to all repositories.
42-
eval cp -rf "output/." "../"
40+
eval ./copy_projects.sh "$@"

0 commit comments

Comments
 (0)