I have some files whose file names are like this:
asdf1.jpg
qer10.jpg
rwytew45.jpg
So, I want to rename all the files that has only one digit to
a two digit number to make them alphabetically correct in
the listing like this: adsf01.jpg
I tried to do it like this:
for($i=0; $i<count($files ); $i++) {
print preg_replace("| (\w+)(\d)(\.jpg )|", "\${1}0\$2\ $3", $files[$i]);
}
but it's not working. It converts all the files like this:
asdf1.jpg => asdf01.jpg
qer10.jpg => qer100.jpg
rwytew45.jpg => rwytew405.jpg
It doesn't seem to care about me wanting only one digit (\d) int the replace.
Any idea how this could be done ?
asdf1.jpg
qer10.jpg
rwytew45.jpg
So, I want to rename all the files that has only one digit to
a two digit number to make them alphabetically correct in
the listing like this: adsf01.jpg
I tried to do it like this:
for($i=0; $i<count($files ); $i++) {
print preg_replace("| (\w+)(\d)(\.jpg )|", "\${1}0\$2\ $3", $files[$i]);
}
but it's not working. It converts all the files like this:
asdf1.jpg => asdf01.jpg
qer10.jpg => qer100.jpg
rwytew45.jpg => rwytew405.jpg
It doesn't seem to care about me wanting only one digit (\d) int the replace.
Any idea how this could be done ?
Comment