#!/bin/bash -l
#SBATCH -o logs/copy-%j.out
#SBATCH -e logs/copy-%j.err
#SBATCH -J copy_results
#SBATCH --mail-type=END,FAIL
#SBATCH --mail-user=user_email
#SBATCH -N1
#SBATCH --cpus-per-task=4
#SBATCH --mem=2000
#SBATCH --time=00:02:00
# This job runs AFTER aggregation is complete
# It copies only the RDS files to a single aggregated directory
module purge
# Create output directory for aggregated results
AGGREGATE_DIR="Results_Aggregated"
mkdir -p "$AGGREGATE_DIR"
# Find all RDS files and copy them while preserving directory structure
echo "Copying RDS files from Results/ to ${AGGREGATE_DIR}/"
# Use parallel copy with find
find Results/ -name "*.rds" -type f | parallel -j 4 'mkdir -p "'$AGGREGATE_DIR'/$(dirname {})" && cp -v {} "'$AGGREGATE_DIR'/{}"'