PHP implementation of Bulk modification of file suffix name method

Source: Internet
Author: User
This article mainly introduces the PHP implementation of bulk modification of file suffix name method, involving PHP recursive traversal and renaming of files related skills, with a certain reference value, the need for friends can refer

In this paper, we describe the method of PHP to implement batch modification of file suffix name. Share to everyone for your reference. Specific as follows:

/** * Bulk Modify file suffix name * @param $path folder path * @param $sext original file suffix ($sext =all all files throughout the directory) * @param $dext destination file suffix * @return void
 */function Foreachdir ($path, $sext, $dext) {   $handle =opendir ($path);   if ($handle) {while   (false!== ($file = Readdir ($handle))) {    if ($file! =). "&& $file! = ' ... ') {     if (Is_dir ($path. $file)) {      Foreachdir ($path. $file);     } else{      $ext = Strripos ($file, '. ');      $fileName = substr ($file, 0, $ext);      $SRC = $path. ' /'. $file;     $dest = $path. ' /'. $fileName. '. $dext;     if ($sext! = "All") {      if ($sext = = substr ($src, 0-strlen ($sext))) rename ($src, $dest);      } else{      Rename ($src, $dest);    }}} return false;   } }foreachdir (' C:\Users\chenlinzhong\Desktop\redis-stable\src ', ' C ', ' txt ');

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.