Skip to content

Instantly share code, notes, and snippets.

@lucassmacedo
Last active June 28, 2023 10:16
Show Gist options
  • Save lucassmacedo/75b448f8d56c9f5bc6efbb9bffeaf1ce to your computer and use it in GitHub Desktop.
Save lucassmacedo/75b448f8d56c9f5bc6efbb9bffeaf1ce to your computer and use it in GitHub Desktop.
Colocar todas as fotos da pasta em pastas por data.
#!/bin/bash
# Pasta contendo as fotos
pasta_fotos="100CANON"
# Lista todas as fotos na pasta (formatos JPG e CR2)
fotos_jpg=("$pasta_fotos"/*.jpg)
fotos_cr2=("$pasta_fotos"/*.cr2)
videos=("$pasta_fotos"/*.mp4)
fotos=("${fotos_jpg[@]}" "${fotos_cr2[@]}" "${videos[@]}")
# Loop sobre cada foto
for foto in "${fotos[@]}"; do
# Obter a data de criação da foto
data=$(exiftool -p '$CreateDate' -d '%Y-%m-%d' "$foto")
# Criar a pasta correspondente à data, se ainda não existir
pasta_destino="$pasta_fotos/$data"
if [ ! -d "$pasta_destino" ]; then
mkdir "$pasta_destino"
fi
# Mover a foto para a pasta correspondente
mv "$foto" "$pasta_destino"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment