Bash: rename dir with suffix

Hi is there a way to rename dir’s with this suffix (Day 01, Day 02, Day 03, …):

original name
dirname = 2013-06-22
dirname = 2013-06-23
dirname = 2013-06-24
dirname = …

wanted name:
dirname = “Day 01 (2013-06-22)”
dirname = “Day 02 (2013-06-23)”
dirname = “Day 03 (2013-06-24)”
dirname = …

now i do the follow:

for DIRNAME in *; do mv $DIRNAME "Day 00 ($DIRNAME); done 

but the result in that way is always “Day 00 …” in that case.

making progress:


count=1

for DIRNAME in *
do

mv $DIRNAME "Day $count ($DIRNAME)"
count=$(( $count + 1 ))

done 

but the result is “Day 1 (2013-06-22)”
instead of “Day 01 …”

(that gives me problems if i have more than 10 dirs)

After the do insert:

(( count < 10 )) && count=0$count

Use “ls -v” to sort the output.

with this code it goes good until “08”, strange problem:

countjpg=1

for DIRNAME in *
do
(( countjpg < 10 )) && countjpg=0$countjpg

mv $DIRNAME "Dag $countjpg ($DIRNAME)"
countjpg=$(( $countjpg + 1 ))

done 

i get this error:

+ countjpg=1
+ for DIRNAME in '*'
+ ((  countjpg < 10  ))
+ countjpg=01
+ mv 2012-09-01 'Dag 01 (2012-09-01)'
+ countjpg=2
+ for DIRNAME in '*'
+ ((  countjpg < 10  ))
+ countjpg=02
+ mv 2012-09-02 'Dag 02 (2012-09-02)'
+ countjpg=3
+ for DIRNAME in '*'
+ ((  countjpg < 10  ))
+ countjpg=03
+ mv 2012-09-03 'Dag 03 (2012-09-03)'
+ countjpg=4
+ for DIRNAME in '*'
+ ((  countjpg < 10  ))
+ countjpg=04
+ mv 2012-09-04 'Dag 04 (2012-09-04)'
+ countjpg=5
+ for DIRNAME in '*'
+ ((  countjpg < 10  ))
+ countjpg=05
+ mv 2012-09-05 'Dag 05 (2012-09-05)'
+ countjpg=6
+ for DIRNAME in '*'
+ ((  countjpg < 10  ))
+ countjpg=06
+ mv 2012-09-06 'Dag 06 (2012-09-06)'
+ countjpg=7
+ for DIRNAME in '*'
+ ((  countjpg < 10  ))
+ countjpg=07
+ mv 2012-09-07 'Dag 07 (2012-09-07)'
+ countjpg=8
+ for DIRNAME in '*'
+ ((  countjpg < 10  ))
+ countjpg=08
+ mv 2012-09-08 'Dag 08 (2012-09-08)'
/usr/local/bin/service-foto_om_weg_te_schrijven_met_exif: regel 249: 08: waarde is te groot voor basis (het onjuiste symbool is "08")
+ qdbus org.kde.kdialog-9333 /ProgressDialog setLabelText 'Hernoemen en mappenstructuur aanmaken voor RAW'


OK found the solution:

countjpg=1

for DIRNAME in *
do
daynumber=`printf %02d $countjpg`
mv $DIRNAME "Dag $daynumber ($DIRNAME)"
countjpg=$(( $countjpg + 1 ))

done 

thanks to give me the right direction :slight_smile:

While you have already found a solution, I did not try to analyze this further. But in the integer expression it takes 08 as being an octal number, which is of course impossible. It would have been better to copy the integer resulot into another varaibale and thre add thye 0 in front. Not using tha other variable in any inetger expressioon then.