Created
October 23, 2011 19:15
-
-
Save MagnusEnger/1307746 to your computer and use it in GitHub Desktop.
Sort pictures into year/month/date folders based on the filename yyyymmdd_x.jpg
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
#!/bin/bash | |
# Read a directory of image files with names on this form: | |
# 20110113_001.jpg | |
# 20110113_002.jpg | |
# 20110113_003.jpg | |
# | |
# Create folders as needed and move the images into them, in this way | |
# 2011 | |
# |__01 | |
# |__13 | |
# |__20110113_001.jpg | |
# |__20110113_002.jpg | |
# |__20110113_003.jpg | |
# | |
# Usage: phosort.sh ~/Pictures | |
cd $1 | |
for f in * | |
do | |
echo $f | |
# Construct the direcory path | |
dir="${f:0:4}/${f:4:2}/${f:6:2}" | |
# Check if the path exists | |
if [ ! -e $dir ] | |
then | |
echo "$dir does not exist" | |
# Create the directory if we have to | |
mkdir -p "$dir" | |
fi | |
# Move the file | |
mv $f $dir/$f | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment