Forum Moderators: coopster

Message Too Old, No Replies

rename()

rename multiple files in web dir using php

         

makimoto

10:03 pm on Mar 18, 2005 (gmt 0)

10+ Year Member



hi,
is it possible to use rename() to rename multiple files in a dir on a web server? i have thousands of jpegs all named with this format: CAP_1111.JPG

my problem is that some of the files are named slightly differently like: cap_1112.JPG, CAP_1113.jpg etc. i want them all to be renamed in this format: CAP_1111.JPG

so i would be changing the file extension case, as well as the "CAP" case. is this possible? i tried looking for some tools that would do it for me, but could not find anything. as well, i looked on php.net manual, but it only shows rename() renaming a single file.

TIA,

dreamcatcher

10:19 pm on Mar 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, firstly to use the rename function your directory would have to be writeable. ie, chmod to 777.

What you need to do then is loop through your directory and perform the rename.

Something like this:


$open = @opendir("directory/");

while ($read = @readdir($open))
{
@rename($read, strtoupper($read));
}

@closedir($open);

I think that should work ok if all you want to do is rename to uppercase.

dc