Last active
January 1, 2016 16:39
-
-
Save gardner/8171792 to your computer and use it in GitHub Desktop.
Rename all files and directories for use with my janky bicycle mp3 player.
This file contains hidden or 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 | |
function rename_usb() { | |
find . -type "$1" | while read -r file; do | |
if [ "$file" -eq ".." | |
newfile=$(echo "$file" | sed 's/[[:space:]]?/_/g | |
#replace " - " with a single underscore. | |
s/[[:space:]]-[[:space:]]/_/g | |
#replace spaces with underscores | |
#replace "-" dashes with underscores. | |
s/-?/_/g | |
#remove exclamation points | |
s/!//g | |
#remove commas | |
s/,//g') | |
if [ -$1 "$newfile" ]; then | |
echo "[WARNING] file exists: $newfile... Skipping." | |
else | |
echo mv "$file" "$newfile" | |
fi | |
done | |
} | |
# first rename all the directories | |
rename_usb 'd' | |
# then all the files | |
rename_usb 'f' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment