Last active
April 28, 2018 11:08
-
-
Save kamontat/97ea3378c5d323b9b430aeda8b5f80df to your computer and use it in GitHub Desktop.
separate images raw files and jpg files
This file contains 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
#!/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