v1.5
Ajout: -aide -tri les dossiers mensuels dans des dossiers annuels
This commit is contained in:
@@ -1,5 +1,29 @@
|
||||
#!/bin/bash
|
||||
|
||||
VERSION=1.5
|
||||
|
||||
#NO_COLOR=1
|
||||
|
||||
# Check if NO_COLOR is set to disable colorization
|
||||
if [ -z "$NO_COLOR" ]; then
|
||||
: "${COLOR_GREEN:=$'\e[32m'}"
|
||||
: "${COLOR_GREEN_BOLD:=$'\e[1;32m'}"
|
||||
: "${COLOR_RED:=$'\e[31m'}"
|
||||
: "${COLOR_RED_BOLD:=$'\e[1;31m'}"
|
||||
: "${COLOR_YELLOW=$'\e[33m'}"
|
||||
: "${COLOR_YELLOW_BOLD:=$'\e[1;33m'}"
|
||||
: "${COLOR_SILVER=$'\e[37m'}"
|
||||
: "${COLOR_LIGHT_GREY=$'\e[249m'}"
|
||||
: "${COLOR_BRIGHT_PURPLE=$'\e[35;1m'}"
|
||||
: "${COLOR_PURPLE=$'\e[35m'}"
|
||||
: "${BOLD:=$'\e[1m'}"
|
||||
: "${ITALIC:=$'\e[3m'}"
|
||||
: "${COLOR_RESET:=$'\e[00m'}"
|
||||
else
|
||||
: "${BOLD:=$'\e[1m'}"
|
||||
: "${COLOR_RESET:=$'\e[00m'}"
|
||||
: "${ITALIC:=$'\e[3m'}"
|
||||
fi
|
||||
|
||||
fr_months=("Janvier" "Février" "Mars" "Avril" "Mai" "Juin" "Juillet" "Août" "Septembre" "Octobre" "Novembre" "Décembre")
|
||||
|
||||
@@ -9,18 +33,59 @@ if ! command -v exiftool &> /dev/null; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Répertoire contenant les photos
|
||||
while :
|
||||
# Help
|
||||
Help() {
|
||||
clear
|
||||
echo -e "\n${COLOR_GREEN_BOLD}Sort Export Folder $VERSION${COLOR_RESET}\n"
|
||||
echo "Syntaxe: sort_export_folder.sh [<folder>]"
|
||||
echo
|
||||
echo "Tri les photos contenues dans un dossier, et selon le mois de prise de vue, les copies dans des dossiers AN/Mois AN"
|
||||
echo "Requiert le tag -CreateDate avec exiftool"
|
||||
echo
|
||||
echo "Options:"
|
||||
echo " -h Affiche l'aide"
|
||||
echo " -d Dossier à trier"
|
||||
echo
|
||||
echo "Exemples: sort_export_folder.sh -d /Volumes/Sophie/Export"
|
||||
echo " sort_export_folder.sh"
|
||||
echo
|
||||
echo "Requiert l'installation de exiftool"
|
||||
echo " -https://exiftool.org"
|
||||
echo " -brew install exiftool"
|
||||
}
|
||||
|
||||
### Parse options
|
||||
|
||||
optspec="fh"
|
||||
while getopts "$optspec" opt
|
||||
do
|
||||
read -e -p "Répertoire contenant les photos: " PHOTO_DIR
|
||||
[ "$PHOTO_DIR" == "q" ] && exit 1
|
||||
if [ "$PHOTO_DIR" != "q" ] && [ -d "$PHOTO_DIR" ]; then
|
||||
break 2
|
||||
fi
|
||||
case ${opt} in
|
||||
d) PHOTO_DIR="${!OPTIND}"; OPTIND=$(( OPTIND + 1 )) ;;
|
||||
h) Help
|
||||
Help
|
||||
exit 2
|
||||
;;
|
||||
*) exit 1 ;;
|
||||
esac
|
||||
done
|
||||
shift $((OPTIND -1))
|
||||
|
||||
|
||||
if [[ -z "$PHOTO_DIR" ]]; then
|
||||
# Répertoire contenant les photos
|
||||
while :
|
||||
do
|
||||
read -e -p "Répertoire contenant les photos: " PHOTO_DIR
|
||||
[ "$PHOTO_DIR" == "q" ] && exit 1
|
||||
if [ "$PHOTO_DIR" != "q" ] && [ -d "$PHOTO_DIR" ]; then
|
||||
break 2
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
nb_jpg_before=$(ls -Uba1 "$PHOTO_DIR" | grep -E -c '.jpg|.jpeg|.cr3|.tif|.dng|.webp|.avif'$)
|
||||
echo "$nb_jpg_before images trouvées dans $PHOTO_DIR"
|
||||
[ $nb_jpg_before -eq 0 ] && exit 3
|
||||
echo
|
||||
|
||||
|
||||
@@ -75,11 +140,47 @@ echo "Triage de $i photos terminé."
|
||||
nb_jpg_after=$(ls -Uba1 "$PHOTO_DIR" | grep -E -c '.jpg|.jpeg|.cr3|.tif|.dng|.webp|.avif'$)
|
||||
echo "$nb_jpg_after images trouvées dans $PHOTO_DIR"
|
||||
|
||||
subfolders=$(ls -A "$PHOTO_DIR" | tr '\n' ', ' | sed 's/.$//')
|
||||
#subfolders=$(ls -A "$PHOTO_DIR" | tr '\n' ', ' | sed 's/.$//')
|
||||
subfolders=$(ls -A "$PHOTO_DIR" | tr '\n' ' ' | sed 's/.$//')
|
||||
|
||||
#####
|
||||
|
||||
echo
|
||||
nb_subfolders=$(ls -l "$PHOTO_DIR" | grep -c ^d)
|
||||
echo "Il y a $nb_subfolders sous-dossiers dans $PHOTO_DIR. Rangeons-les par année !"
|
||||
|
||||
for DIR in "$PHOTO_DIR"/*; do
|
||||
|
||||
if [[ -d "$DIR" ]]; then
|
||||
year=$(basename "$DIR" | awk -F" " '{print $2}')
|
||||
new_year+=(${year})
|
||||
if [[ -n "$year" ]]; then
|
||||
# Créer le répertoire pour l'année correspondante
|
||||
YEAR_DIR="$PHOTO_DIR/$year"
|
||||
|
||||
mkdir -p "$YEAR_DIR"
|
||||
|
||||
mv "$DIR" "$YEAR_DIR/" &
|
||||
#echo "Déplacé : $DIR -> $YEAR_DIR/"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
nb_year_folders=$(ls -l "$PHOTO_DIR" | grep -c ^d)
|
||||
#year_folders=$(ls -d *)
|
||||
year_folders=$(cd "$PHOTO_DIR"; ls -d * | tr '\n' ' ')
|
||||
echo "$nb_year_folders sous-répertoires $year_folders crées."
|
||||
|
||||
###
|
||||
nb_jpg_id_dest=$(find "$PHOTO_DIR" -mindepth 2 -type f -exec bash -c 'echo ${0%${0#$1}}' {} "$PHOTO_DIR" \; | uniq -c | awk '{print $1}')
|
||||
echo "$nb_jpg_id_dest images trouvées dans les sous-répertoires $subfolders"
|
||||
|
||||
[ $nb_jpg_after -ne 0 ] && echo "Erreur !! Il reste des photos dans le dossier d'origine."
|
||||
[ $nb_jpg_before -ne $nb_jpg_id_dest ] && echo "Erreur !! Toutes les photos n'ont pas été déplacées."
|
||||
|
||||
echo
|
||||
tr=$(tree -d "$PHOTO_DIR" | head -n -1)
|
||||
echo -e "${COLOR_PURPLE}$tr${COLOR_RESET}"
|
||||
tree -a "$PHOTO_DIR" | tail -n 1
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user