- Add script to recursively copy .o files from build directory - Support command line arguments for source and target directories - Handle duplicate filenames with auto-incrementing suffix - Update README with usage documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
45 lines
1.1 KiB
Bash
Executable File
45 lines
1.1 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
if [ $# -lt 2 ]; then
|
|
echo "用法: $0 <源目录> <目标目录>"
|
|
echo "示例: $0 /path/to/build /path/to/output"
|
|
exit 1
|
|
fi
|
|
|
|
SOURCE_DIR="$1"
|
|
TARGET_DIR="$2"
|
|
|
|
if [ ! -d "$SOURCE_DIR" ]; then
|
|
echo "错误: 源目录不存在: $SOURCE_DIR"
|
|
exit 1
|
|
fi
|
|
|
|
mkdir -p "$TARGET_DIR"
|
|
|
|
echo "开始复制 .o 文件..."
|
|
|
|
find "$SOURCE_DIR" -name "*.o" -type f | while read -r file; do
|
|
basename=$(basename "$file")
|
|
base="${basename%.*}"
|
|
ext="${basename##*.}"
|
|
|
|
if [ -f "$TARGET_DIR/$basename" ]; then
|
|
counter=1
|
|
new_name="${base}_${counter}.${ext}"
|
|
|
|
while [ -f "$TARGET_DIR/$new_name" ]; do
|
|
((counter++))
|
|
new_name="${base}_${counter}.${ext}"
|
|
done
|
|
|
|
cp "$file" "$TARGET_DIR/$new_name"
|
|
echo "复制: $file -> $TARGET_DIR/$new_name (重名文件)"
|
|
else
|
|
cp "$file" "$TARGET_DIR/$basename"
|
|
echo "复制: $file -> $TARGET_DIR/$basename"
|
|
fi
|
|
done
|
|
|
|
echo "复制完成!"
|
|
echo "已复制的文件在: $TARGET_DIR"
|
|
ls -la "$TARGET_DIR"/*.o | wc -l |