Last active
September 13, 2017 13:19
-
-
Save jamestomasino/6345336521004401486d93624b2667ab to your computer and use it in GitHub Desktop.
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 -e | |
ROOT="/home/tomasino/movies" | |
SAVEIFS=$IFS | |
IFS=$(echo -en "\n\b") | |
# First loop to rename files | |
for f in $(find "$ROOT" -mindepth 1 -maxdepth 1 -type f -not -path '**/batchrename.sh' -not -path '**/.DS_Store'); do | |
# Wrap dates in parens if needed | |
rename -e 's/(?<!\()(\d{4})(?!\))/($1)/s' "$f" | |
done | |
# Second loop to move files | |
for f in $(find "$ROOT" -mindepth 1 -maxdepth 1 -type f -not -path '**/batchrename.sh' -not -path '**/.DS_Store'); do | |
# Get just filename | |
t=$(basename $f) | |
# Get filename without extension | |
p="${t%%)*})" | |
# Create directory, if needed | |
if [ ! -d "$p" ]; then | |
echo "Create Directory: $p" | |
cd "$ROOT" && mkdir -p "$p" && cd - | |
fi | |
# Move the file to the new folder | |
mv "$f" "$ROOT/$p" | |
done | |
IFS=$SAVEIFS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment