欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

一个批量修改文件后缀名的php函数

程序员文章站 2022-04-24 10:44:05
...
  1. /**
  2. * 批量修改文件后缀名
  3. * func: foreachDir
  4. */
  5. function foreachDir($path){
  6. $handle=opendir($path);
  7. if($handle){
  8. while (false !== ($file = readdir($handle))) {
  9. if($file!="." && $file!='..'){
  10. if(is_dir($path.$file)){
  11. echo $path.$file."
    ";
  12. foreachDir($path.$file);
  13. }else{
  14. echo "--".$path."/".$file."
    ";
  15. $ext = strripos($file,'.');
  16. $aaa = substr($file,0,$ext);
  17. rename($path.'/'.$file,$path.'/'.$aaa.'.JPG');
  18. // die();
  19. }
  20. }
  21. }
  22. return false;
  23. }
  24. }
  25. foreachDir('D:\xampp\htdocs\TNF2');
  26. ?>
复制代码