Hi. I have a bunch of tif images in the directory with the following naming convention:
1.tif
2.tif
3.tif
.
.
.
n.tif
There are over 1000 tif images in this dir. I'm running a for loop to rename *.tif in this dir to <YYYYMMDD><NNNN>.tif, where YYYYMMDD is the current date (duh), and NNNN is a 4-digit sequence number beginning with 1 and incrementing with each tif image.
I also have an input csv file that references the images. I'm reformatting the csv file and including it in a zip file at the end of processing, which also contains the re-named zip files.
The problem I'm having is that the output csv matches the data in the input csv (and re-formatted properly), but the transactions in the output csv reference the wrong images.
I've discovered that the problem is in the For loop. This is the code:
cd $IMGPATH
for file in $IMGPATH/*.tif ; do
count=$((count + 1))
count_str=$(printf "%04d" $count)
mv $file $LBOX$DATEDIR$count_str"0.tif"
done
The problem is that this sequences the files in the following order:
1.tif
10.tif
100.tif
1000.tif
etc
So my second transaction in the output csv file references the 10th image in the directory, the 3rd transaction in the csv file references the 100th image in the directory, and so on.
How do I make the loop sort by image number properly?