Implementation code for batch replacement of file names in php. Copy the code as follows: $ dirD: ProgramFilesresourceapplicationSkinPNG \; note that two paths must be added. The first one indicates the conversion, but the code is as follows:
The code is as follows:
$ Dir = 'd: \ Program Files \ resource \ application \ Skin \ PNG \ '; // note the path here. add two \ s to the end. The first one indicates the conversion, however, in this case, it is easy to encounter other specific escape characters. you must make a careful judgment as follows:
$ Dir = 'd:/Program Files/resource/application/Skin/PNG/'; // write this path, so you don't have to worry about escape. Last/do not miss writing
If ($ dh = opendir ($ dir ))
{
While ($ file = readdir ($ dh ))! = False)
{
If ($ file! = "." & $ File! = "..")
{
If (filetype ($ dir. $ file) = 'file ')
{
$ Newfile = str_replace (array ('_ PNG', '_ XML',' _ ICO '), array ('. PNG ','. XML ','. ICO '), $ file );
Var_dump ($ file. '======>'. $ newfile .'
');
Rename ($ dir. $ file, $ dir. $ newfile );
}
}
}
Closedir ($ dh );
}
The export code is as follows: $ dir = 'd: \ Program Files \ resource \ application \ Skin \ PNG \ '; // note the path here, and add two \, the first one indicates a conversion, but the content...