Here's what I'd like to do in pseudocode:
for subdir in [all first-level subdirectories of the current directory]:
for file in [all files in subdir]:
rename file to "myprefix_" + current_filename_padded_with_zeroes
What I mean by current_filename_padded_with_zeroes
is e.g. if the current filename is 01.png
change to 0001.png
, or 100.png
change it to 0100.png
.
Can anyone help me translate the above into a bash script?
Something like... I'm not sure how to do the renaming part:
#!/bin/bash
for DIR in $(ls)
do
for FILENAME in $(ls $DIR)
do
mv "$FILENAME" "myprefix_{%FILENAME}"
done
done