When dealing with iOS app bundle, It is not convenient to get the file by its path, but loading it by its name.
Need to batch rename images recursively, with Mac Bash. And to make the name unique, the directory index should be numbered.
To rename files ,turn
Root----A----0.png
| |
| ----C----9.png
|
-------B----0.png
|
-------0.png
|
-------0.sh
to
Root----A----1_0.png
| |
| ----C----3_9.png
|
-------B----2_0.png
|
-------0_0.png
|
-------0.sh
Just to rename the .png
files. Keep the other file's name before.
Here is my code, it is ok to deal with the situation that dir
A has a name of spacing.
n=0
rename(){
varN=$n
for f in * ; do
if [[ -f $f ]]; then
extension="${f##*.}"
if [[ $extension == "png" ]]; then
mv "$f" $n"_$f"
(( varN++ ))
fi
fi
done
if (( $varN > $n )); then
((n++))
fi
for d in */ ; do
( cd "$d" && rename)
(( n++ ))
done
}
rename
Any way to make it more brilliant?