Home >Backend Development >PHP Tutorial >A php function that batches changes to file extensions

A php function that batches changes to file extensions

WBOY
WBOYOriginal
2016-07-25 09:03:24896browse
  1. /**
  2. * Modify file extensions in batches
  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:xampphtdocsTNF2');
  26. ?>
复制代码


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn