Skip to content

Instantly share code, notes, and snippets.

@jagipson
Created July 14, 2011 23:59
Show Gist options
  • Save jagipson/1083757 to your computer and use it in GitHub Desktop.
Save jagipson/1083757 to your computer and use it in GitHub Desktop.
JPG Renamer
#!/bin/bash
basedir=/tmp/testscript/working/Images
pushd "$basedir" &>/dev/null
# Loop over all dirs with names in front
for dirname in $(find ./apteryx -maxdepth 1 -type d -iregex '\./[a-z].*')
do
patnum=$(echo $dirname | sed 's/^.*_\([0-9]\+\)/\1/')
if grep -qv '^[[:digit:]]\+$' <<<$patnum
then
echo "Warning: error parsing directory $dirname, got '$patnum'; skipping"
continue
elif [[ ! -d "$patnum" ]]
then
echo "Warning: unable to find destination folder $basedir/$patnum"
continue
else
set -o xtrace
find $patnum -regextype posix-awk -iregex .*/[0-9]{2}-[0-9]{2}-[0-9].*.jpg -type f # -exec ln {} ./apteryx/$dirname/ \;
set +o xtrace
fi
done
popd &>/dev/null
@jagipson
Copy link
Author

find /tmp/testscript/ -type f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment