Last active
May 10, 2016 14:32
-
-
Save ralphcrisostomo/0d262aa8b04da15089f217793723abeb to your computer and use it in GitHub Desktop.
Script to organize pictures and videos
This file contains hidden or 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
#!/bin/bash | |
# Script to organize pictures and videos | |
# By Ralph Crisostomo - 2016.05.10 | |
# | |
# Usage : | |
# sudo ./move_picture.sh "GM1 - Day 01" | |
# | |
_destination="$1" | |
_date=$(date +"%Y%m%d") | |
_images_dir="$PWD/$_date - $_destination/images" | |
_videos_dir="$PWD/$_date - $_destination/videos" | |
_videos_ext=( "mov" "mp4" "avi" "mkv" "mts" "MOV" "MP4" "AVI" "MKV" "MTS" ) | |
_images_ext=( "jpg" "png" "JPG" "PNG" ) | |
_images_count=0 | |
_videos_count=0 | |
# | |
# Create directory | |
# | |
[[ -d "$_images_dir" ]] || mkdir -p "$_images_dir" | |
[[ -d "$_videos_dir" ]] || mkdir -p "$_videos_dir" | |
while IFS= read -d '' -r ITEM | |
do | |
_filename=$(basename "$ITEM") | |
_extension="${_filename##*.}" | |
_filename="${_filename%.*}" | |
# | |
# Copy files | |
# | |
if [[ ${_images_ext[*]} =~ $_extension ]]; then | |
_images_count=$(( $_images_count + 1 )) | |
_dir="$_images_dir" | |
else | |
_videos_count=$(( $_videos_count + 1 )) | |
_dir="$_videos_dir" | |
fi | |
echo "$ITEM -> $_dir" | |
cp "$ITEM" "$_dir" | |
done< <(find -E "$PWD" \( -regex '.*\.(jpg|png|JPG|PNG|avi|mts|mov|mp4|mkv|AVI|MTS|MP4|MOV|MKV)' \) -print0 ) | |
printf "\nTotal images: $_images_count" | |
printf "\nTotal videos: $_videos_count\n" | |
# | |
# Adding total count | |
# | |
mv "$_images_dir" "$_images_dir - ($_images_count)" | |
mv "$_videos_dir" "$_videos_dir - ($_videos_count)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment