Skip to content

Instantly share code, notes, and snippets.

@kamontat
Last active April 28, 2018 11:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kamontat/97ea3378c5d323b9b430aeda8b5f80df to your computer and use it in GitHub Desktop.
Save kamontat/97ea3378c5d323b9b430aeda8b5f80df to your computer and use it in GitHub Desktop.
separate images raw files and jpg files
#!/usr/bin/env bash
# set -x #DEBUG - Display commands and their arguments as they are executed.
# set -v #VERBOSE - Display shell input lines as they are read.
# set -n #EVALUATE - Check syntax of the script but don't execute.
# -------------------------------------------------
# Create by: Kamontat Chantrachirathumrong
# -------------------------------------------------
# Version: 0.0.1 -- finish
# 1.0.0 -- refactor code
# -------------------------------------------------
location="$1"
# default location is current dir
test -z "$location" && location="$PWD"
# check location
[ -d "$location" ] || exit 1
cd "$location" || exit 2
get_extension() {
extension="${1##*.}"
filename="${1%%.*}"
export EXTENSION="$extension"
export FILENAME="$filename"
}
postfix="_folder"
for file in "$location"/*; do
get_extension "$file"
folder="${EXTENSION}${postfix}"
# create folder if not exist
! test -d "${PWD}/${folder}" &&
mkdir "${PWD}/${folder}" 2>/dev/null
printf "move $file => $folder "
mv "$file" "${PWD}/${folder}/" &&
echo "COMPLETED" ||
echo "ERROR"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment