Not very often processing files, so the traversal directory is not very familiar with, looking for information, modify their own.
Let's see if we need a perfect
The main purpose of the code is to change the file suffix in bulk because of the different types of Taobao package pictures to change the appropriate.
Copy Code code as follows:
<?php
//This file and the files under the directory to be changed are placed under the same folder
define ("STA", ". gif");// The original file format
define ("End", ". jpg");//format to change
$dir = "./";
$arr =allfile ($dir);
foreach ($arr as $t)
{
$t =str_replace (".//", "", $t);
if (Substr_count ($t, STA) >0)
{
$f 2=str_replace (STA, "", $t);
Rename ($t, $f 2. End);
}
}
//Get functions for all files under directory
function Allfile ($dir)
{
$files =array ();
if (Is_file ($dir))
{
return $dir;
}
$handle = Opendir ($dir);
if ($handle) {
while (false!== ($file = Readdir ($handle)) {
if ($file!= '. ' && $file!= ' ... ') {
$filename = $dir. "/" . $file;
if (Is_file ($filename)) {
$files [] = $filename;
}else {
$files = Array_merge ($files, Allfile ($filename));
}
}
}//End While
Closedir ($handle);
}
Return $files;
}
?>