php實現(xiàn)批量修改文件名稱的方法
本文實例講述了php實現(xiàn)批量修改文件名稱的方法。分享給大家供大家參考,具體如下:
<?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); } ?>
更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《php文件操作總結(jié)》、《php正則表達式用法總結(jié)》、《php操作office文檔技巧總結(jié)(包括word,excel,access,ppt)》、《PHP數(shù)組(Array)操作技巧大全》、《php排序算法總結(jié)》、《PHP常用遍歷算法與技巧總結(jié)》、《PHP數(shù)據(jù)結(jié)構(gòu)與算法教程》、《php程序設(shè)計算法總結(jié)》、《PHP數(shù)學(xué)運算技巧總結(jié)》、《PHP運算與運算符用法總結(jié)》、《php字符串(string)用法總結(jié)》及《php常見數(shù)據(jù)庫操作技巧匯總》
希望本文所述對大家PHP程序設(shè)計有所幫助。
相關(guān)文章
PHP微信開發(fā)用Cache 解決數(shù)據(jù)緩存
本文主要介紹,解決PHP微信開發(fā)時數(shù)據(jù)緩存的問題,這里用Cache 類舉例說明,具有參考價值,感興趣的小伙伴可以參考下2016-07-07PHP實現(xiàn)字符串大小寫轉(zhuǎn)函數(shù)的功能實例
這篇文章主要給大家介紹了關(guān)于利用PHP如何實現(xiàn)字符串大小寫轉(zhuǎn)函數(shù)功能的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友一起來看看啊2019-02-02解析Extjs與php數(shù)據(jù)交互(增刪查改)
本篇文章是對Extjs與php數(shù)據(jù)交互(增刪查改)進行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06PHP實現(xiàn)基于圖的深度優(yōu)先遍歷輸出1,2,3...n的全排列功能
這篇文章主要介紹了PHP實現(xiàn)基于圖的深度優(yōu)先遍歷輸出1,2,3...n的全排列功能,涉及php數(shù)據(jù)結(jié)構(gòu)中圖的遍歷及全排列相關(guān)數(shù)學(xué)運算技巧,需要的朋友可以參考下2017-11-11php使用json-schema模塊實現(xiàn)json校驗示例
這篇文章主要介紹了php使用json-schema模塊實現(xiàn)json校驗,結(jié)合實例形式分析了json-schema模塊的安裝及使用json-schema模塊進行json校驗的相關(guān)操作技巧,需要的朋友可以參考下2019-09-09