How do I sort the folder before I find all the images in it?
My folders looks like this:
- {sku-num}-{productname}
- {sku-num}-2{productname}
- {sku-num}-3{productname}
For example:
: 123456-myproduct.jpg
: 123456-2-myproduct.jpg
So the 'main' or featured image is always the first one, all other images are numbered.
I have a txt file with all sku's where I'm looping through all files to search all the images. But when I execute, I get all images in the wrong order.
I want this
123456, 123456-myproduct.jpg, 123456-2-myproduct.jpg
But half the time I get it reversed, meaning I get the second image in the position what would be the 'main' image.
This is my current code
while read p; do
final="$p"
for i in `find /Users/user/Desktop/img_sorted -name *$p* `
do final+=", $(basename $i)"
done
echo $final
done </Users/user/Desktop/img/skus.txt
I need my folder to be sorted so I can just simply get the first image.