Skip to content

Instantly share code, notes, and snippets.

@shedali
Last active May 1, 2016 19:59
Show Gist options
  • Save shedali/ceef1d914c05aa78f1c5 to your computer and use it in GitHub Desktop.
Save shedali/ceef1d914c05aa78f1c5 to your computer and use it in GitHub Desktop.
sort whatsapp to dated subfolders
#!/bin/bash
echo running;
find . -maxdepth 3 -regex ".*\-2016[0-9][0-9][0-9][0-9].*.*" | while read filename;
do
f=$(basename "$filename")
echo $f
date=$(echo "$f" | cut -c5-12)
echo $date
if echo "${date}" | grep '[0-9]' >/dev/null; then
dirpath='/Users/shedali/Dropbox/Events/2016/'${date:0:4}-${date:4:2}-${date:6:2}
echo makedir "$dirpath"
mkdir -p "$dirpath"
echo mo "$filename" ${dirpath}
mv "$filename" "${dirpath}"
else
echo 'Invalid input'
echo "${date}" | grep '[0-9]'
exit 1
fi
done
# directory=${file%.pdf}
# mv "$filename" "$directory"/"$filename"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment