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