Created
May 19, 2014 21:35
-
-
Save REPOmAN2v2/2402f3b4acf3e4a8f210 to your computer and use it in GitHub Desktop.
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 | |
#this is what i am trying in c right now, but i think some of you guys can solve this with a small shell script | |
#i got the following folder structure: | |
#reaction pics | |
#-laughing | |
#->12321.jpg | |
#->321312.jpg | |
#-wat | |
#->4123.png | |
#->2.gif | |
#-smug faces | |
#->21321.bmp | |
#->123.jpg | |
#you get the picture, there is a folder for each group of reaction faces. what i want to do is to go though the folder structure #recusively and name the pictures in the folders like this: | |
#laughing_1.jpg, laughing_2.png and so on, you get the name from the folder name above the picture.. | |
#this way you have representative names for the pictures and you dont need the folders anymore | |
#THIS SCRIPT WILL ONLY WORK CORRECTLY IF PLACED INTO THE DIRECTORY YOU WANT SORTED ('reaction pics' in the spec) | |
#FIRST RUN WILL SPIT OUT ALL THE FILE RENAMES THAT WOULD BE MADE IF THE 'MV' LINE WERE UNCOMMENTED | |
for dir in ./*; do | |
[[ -d "$dir" ]] || continue | |
cd "$dir" | |
number=1 | |
for file in *; do | |
[[ "$file" == '*' ]] && continue | |
echo "$file -> ${dir}_${number}.${file##*.}" | |
#mv "$file" "${dir}_${number}.${file##*.}" #comment this out after you've checked the dry-run output | |
number=$(( number + 1 )) | |
done | |
cd - >/dev/null | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment