How to sequentially rename files (in PHP) that carry on from a sequence of already existing files? -


say have source folder bunch of files in this

0_0.jpg 0_1.jpg 0_2.jpg 0_3.jpg 1_0.jpg 1_1.jpg 1_2.jpg 1_3.jpg 2_0.jpg 2_1.jpg 2_2.jpg 2_3.jpg 

and have target folder has exact same filenames in it.

how can add files source folder target folder filenames come out this:

0_0.jpg 0_1.jpg 0_2.jpg 0_3.jpg 1_0.jpg 1_1.jpg 1_2.jpg 1_3.jpg 2_0.jpg 2_1.jpg 2_2.jpg 2_3.jpg ---------- files source folder 3_0.jpg 3_1.jpg 3_2.jpg 3_3.jpg 4_0.jpg 4_1.jpg 4_2.jpg 4_3.jpg 5_0.jpg 5_1.jpg 5_2.jpg 5_3.jpg 

is there reasonable way to in php ?

use scandir (http://php.net/scandir) loop through files , last file in first directory. parse out numbers determine starting path second directory. loop through files in second directory , rename (http://php.net/rename).

edit:

as suggested @toby in comments,

split('_',$var) return array of items in string divided on _ allowing easy access 2 numbers in filename


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -