Skip to content

Instantly share code, notes, and snippets.

@ybv
Created December 27, 2013 00:44
Show Gist options
  • Select an option

  • Save ybv/8140873 to your computer and use it in GitHub Desktop.

Select an option

Save ybv/8140873 to your computer and use it in GitHub Desktop.
A script to move folders containing .mp3 files to user's own music folder. Often, downloaded music on my mac rests in downloads, thought this would be handy to move all of them at once.
#!/usr/bin/nv bash
directory=$PWD
dot="."
ddot=".."
myarray=(`find $directory -type f -name "*.mp3"`)
if [ ${#myarray[@]} -gt 0 ]; then
for name in ${myarray[@]}; do
if [[ "$(dirname $name)" != "$dot" ]]; then
rsync -aq --progress $(dirname $name) "/Users/ybv/music"
fi
done
for name in ${myarray[@]}; do
if [[ "$(dirname $name)" != "$dot" ]]; then
if [[ "$(dirname $name)" != "$ddot" ]]; then
rm -rf $(dirname $name)
fi
fi
done
else
echo false
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment