I have 2 folder structure like this:
SOURCE_FOLDER_W_GOOD_NAMES
├── A_some_name.png
├── B_another_different_name.png
├── C_just_another_too.png
└── D_this_one_stop_this_example.png
Another folder:
DESTINATION_FOLDER_W_INCREMENT_NAMES
├── icon_0.icns
├── icon_1.icns
├── icon_2.icns
└── icon_3.icns
So basically, SOURCE_FOLDER
already contains the files which are sorted in alphabetical order. This sort order is already matched with DESTINATION_FOLDER
(eg: A_some_name.png
=== icon_0.icns
)
I'm using this loop combination to rename the files:
i=0
j=0
for img in SOURCE_FOLDER/*.png; do
for i in {0..10000}; do
let j++ || true;
mv "SOURCE_FOLDER/icon_$i.icns" "DESTINATION_FOLDER/${img%.*}.icns"
done
done
I executed this on the command line (the above is formatted, I'm a one-liner guy) in the root of the above folder.
THE_FATHER_FOLDER
├── SOURCE_FOLDER_W_GOOD_NAMES
└── DESTINATION_FOLDER_W_INCREMENT_NAMES
Unfortunately, the above loop is not working as I expected. I'm certain that I'm wrong but I don't know where.
Please correct me.
UPDATED
Solution for the above question, I solved it myself
counter=0
for img in SOURCE_FOLDER/*.png; do
let counter++ || true;
mv "SOURCE_FOLDER/icon_$counter.icns" "DESTINATION_FOLDER/${img%.*}.icns"
done
But I have another question, in this folder:
DESTINATION_FOLDER_W_INCREMENT_NAMES
├── icon_0.icns
├── icon_1.icns
├── icon_2.icns
└── icon_3.icns
I want to reindex it from 1 instead of 0, thus I'm using this:
counter=0
for index in {0..final_number}; do
let counter++ || true;
mv "icon_${index}.icns" "icon_${counter}.icns";
done
At the moment, my files are started from 0 and ended up by final_number - 1, so it will overwrite every single-file I have in this folder and I got only the first file (icon_0) which renamed to (icon_final_number) when it's done.
How could I resolve this?