Created
July 6, 2017 18:28
-
-
Save modpluz/6890f56dca1e5ec79b86174bb4739853 to your computer and use it in GitHub Desktop.
Copy media files and create directory if necessary
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
#!/usr/bin/env bash | |
shopt -s globstar | |
numberRegex='^[0-9]+$' | |
for d in static/* static/**/* ; do | |
if [ -d ${d} ]; then | |
bn=$(basename $d) | |
# We only care about media resources | |
if [[ "$bn" = "images" || ("$bn" = "videos" || "$bn" = "sounds") ]]; then | |
for filepath in $(ls $d) ; do | |
mediaId="${filepath%.*}" | |
if ! [[ $mediaId =~ $numberRegex ]] ; then | |
mediaDir="/media/$mediaId" | |
# create directory if it doesn't exist | |
if [ ! -d "$mediaDir" ]; then | |
mkdir "$mediaDir" | |
fi | |
# copy file | |
cp "$d/$filepath" "$mediaDir/$filepath" | |
fi | |
done | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment