View Full Version : Rename all files in directory to lowercase

01-17-2010, 09:14 AM

I have a list of images in my directory that are in link with my database, and are case sensitive. Some of them (well a vast majority) have uppercase letters, and I need them all to be lowercase. Can somebody start the script off for me of how I could go about doing this?

Thanks much,

Len Whistler
01-17-2010, 09:22 AM
If your on Linux here is a tested shell script.



for f in *; do
g=`expr "xxx$f" : 'xxx\(.*\)' | tr '[A-Z]' '[a-z]'`
mv "$f" "$g"

Here is untested php script.

$files = scandir($directory);
foreach($files as $key=>$name){
$oldName = $name;
$newName = strtolower($name);


01-17-2010, 09:27 AM
:( No, I'm not. Thanks very much for your effort though! Appreciated.

function dirList ($directory)

// create an array to hold directory list
$results = array();

// create a handler for the directory
$handler = opendir($directory);

// keep going until all files in directory have been read
while ($file = readdir($handler)) {

// if $file isn't this directory or its parent,
// add it to the results array
if ($file != '.' && $file != '..')
$results[] = $file;

// tidy up: close the handler

// done!
return $results;

$arr = dirList("images");
foreach ($arr as $key => $value) {
$value2 = strtolower($value);

Perhaps something like that? Anybody got any better ideas?

01-17-2010, 10:50 AM
Len's second example would work fine for you. It is essentially identical to what you've come up with in your example above, the only difference being that unnecessary dirList() function.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum