Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Script to organize pictures and videos
#!/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
You can’t perform that action at this time.