源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

php实现批量修改文件名称的方法

  • 时间:2020-07-25 03:55 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:php实现批量修改文件名称的方法
本文实例讲述了php实现批量修改文件名称的方法。分享给大家供大家参考,具体如下:
<?php
session_start();
set_time_limit(0);
//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;
//
// }
// $dir="./*";
//print_r(allfile($dir));
$path = '.';
function get_filetree($path){
 $tree = array();
 foreach(glob($path.'/*') as $single){
  if(is_dir($single)){
   $tree = array_merge($tree,get_filetree($single));
  }
  else{
   $tree[] = $single;
  }
 }
 return $tree;
}
$dir_arr=get_filetree($path);
$dir_arr_count=count($dir_arr);
//echo $dir_arr_count."<br />";
for($i=0;$i<$dir_arr_count;$i++){
  $file_name= $dir_arr[$i];
  echo $file_name."<br />";
    $file=basename($file_name);
    //echo $file."<br />";
    $dir_arr_0_=explode($file,$file_name);
    $dir_arr_0_0=$dir_arr_0_[0];
    $file_arr=explode("[1]",$file);
    ////rename
    $file_new_name=$file_arr[0].$file_arr[1];
    rename($file_name,$dir_arr_0_0.$file_new_name);
  }
?>

更多关于PHP相关内容感兴趣的读者可查看本站专题:《[url=http://www.1sucai.cn/Special/59.htm]php文件操作总结[/url]》、《[url=http://www.1sucai.cn/Special/180.htm]php正则表达式用法总结[/url]》、《[url=http://www.1sucai.cn/Special/339.htm]php操作office文档技巧总结(包括word,excel,access,ppt)[/url]》、《[url=http://www.1sucai.cn/Special/623.htm]PHP数组(Array)操作技巧大全[/url]》、《[url=http://www.1sucai.cn/Special/150.htm]php排序算法总结[/url]》、《[url=http://www.1sucai.cn/Special/242.htm]PHP常用遍历算法与技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/614.htm]PHP数据结构与算法教程[/url]》、《[url=http://www.1sucai.cn/Special/111.htm]php程序设计算法总结[/url]》、《[url=http://www.1sucai.cn/Special/630.htm]PHP数学运算技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/357.htm]PHP运算与运算符用法总结[/url]》、《[url=http://www.1sucai.cn/Special/47.htm]php字符串(string)用法总结[/url]》及《[url=http://www.1sucai.cn/Special/231.htm]php常见数据库操作技巧汇总[/url]》 希望本文所述对大家PHP程序设计有所帮助。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部