Created
May 30, 2023 09:46
-
-
Save silvtal/86b265d173528b794dbe92a36ecd9f58 to your computer and use it in GitHub Desktop.
Move all folders inside a parent folder into a new parent folder. If there alre conflicts, only move those folders that are bigger than the existing ones.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source_folder="old_results_2023-04-13" | |
destination_folder="new_results_2023-05-30" | |
for file in "$source_folder"/*; do | |
filename=$(basename "$file") | |
destination_file="$destination_folder/$filename" | |
if [[ -e "$destination_file" ]]; then | |
source_size=$(stat -c%s "$file") | |
destination_size=$(stat -c%s "$destination_file") | |
echo $source_size $destination_size | |
if [[ $source_size -gt $destination_size ]]; then | |
echo "Replacing $filename..." | |
mv -f "$file"/* "$destination_file" | |
else | |
echo "Keeping existing $filename..." | |
fi | |
else | |
echo "Moving $filename..." | |
mkdir "$destination_file" | |
mv -f "$file"/* "$destination_file" | |
fi | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment