在php中删除目录如果是空目录我们可直接使用rmdir来删除,但是要删除非空目录我们需要先删除最子级目录的文件然后再删除空目录,其实就是递归删除目录了.
循环删除目录和文件函数,代码如下:
- function delDirAndFile( $dirName )
- {
- if ( $handle = opendir( “$dirName” ) ) {
- while ( false !== ( $item = readdir( $handle ) ) ) {
- if ( $item != “.” && $item != “..” ) {
- if ( is_dir( “$dirName/$item” ) ) {
- delDirAndFile( “$dirName/$item” );
- } else {
- if( unlink( “$dirName/$item” ) )echo “成功删除文件: $dirName/$item
- n”;
- }
- }
- }
- closedir( $handle );
- if( rmdir( $dirName ) )echo “成功删除目录: $dirName
- n”;
- }
- }
- ?>
循环目录下的所有文件,代码如下:
- function delFileUnderDir( $dirName=”../Smarty/templates/templates_c” )
- {
- if ( $handle = opendir( “$dirName” ) ) {
- while ( false !== ( $item = readdir( $handle ) ) ) {
- if ( $item != “.” && $item != “..” ) {
- if ( is_dir( “$dirName/$item” ) ) {
- delFileUnderDir( “$dirName/$item” );
- } else {
- if( unlink( “$dirName/$item” ) )echo “成功删除文件: $dirName/$item
- n”;
- }
- }
- }
- closedir( $handle );
- }
- }
- ?>
目录删除函数,代码如下:
- function my_del_dir($directory)
- {
- if (is_dir($directory) == false)
- {
- exit("The Directory Is Not Exist!");
- }
- $handle = opendir($directory);
- while (($file = readdir($handle)) !== false)
- {
- if ($file != "." && $file != "..")
- {
- is_dir("$directory/$file")?
- my_del_dir("$directory/$file"):
- unlink("$directory/$file");
- }
- }
- if (readdir($handle) == false)
- {
- closedir($handle);
- rmdir($directory);
- }
- }
- ?>
自己写的一个,$sourceDir 要删除的目录路径.
调用方法:DeleteDir(“images/abc”);删除abc目录,代码如下:
- function DeleteDir($sourceDir){
- $succeed = true;
- if(file_exists($sourceDir)){
- $objDir = opendir($sourceDir);
- while(false !== ($fileName = readdir($objDir))){
- if(($fileName != “.”) && ($fileName != “..”)){
- chmod(“$sourceDir/$fileName”,0777);
- if(!is_dir(“$sourceDir/$fileName”)){
- if(!unlink(“$sourceDir/$fileName”)){
- $succeed = false;
- break;
- }
- }
- else{
- DeleteDir(“$sourceDir/$fileName”);
- }
- }
- }
- if(!readdir($objDir)){
- closedir($objDir);
- if(!rmdir($sourceDir)){
- $succeed = false;
- }
- }
- }
- return $succeed;
- }
波比源码 – 精品源码模版分享 | www.bobi11.com
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
7. 本站源码并不保证全部能正常使用,仅供有技术基础的人学习研究,请谨慎下载
8. 如遇到加密压缩包,请使用WINRAR解压,如遇到无法解压的请联系管理员!
波比源码 » php 删除非空目录自定义函数
波比源码 » php 删除非空目录自定义函数
order levaquin 500mg generic buy levaquin generic
avodart over the counter buy tamsulosin generic cheap ondansetron 8mg
acillin brand erythromycin drug erythromycin 500mg canada
buy sildenafil 100mg pill purchase nolvadex pills buy robaxin online cheap
order sildenafil 100mg pills sildenafil 100mg generic estrace order online
buy lamictal 50mg pill buy vermox online buy tretinoin generic
order tadalafil 20mg sale tadalafil 10mg sale voltaren 100mg ca
purchase indocin online cheap indomethacin 50mg tablet trimox 250mg pills
generic tadalafil 40mg cialis by mail cheap viagra online
acheter 40mg gГ©nГ©rique tadalafil en france tadalafil 40mg prix sildenafil prix
tadalafil ohne rezept viagra kaufen ohne rezept sildenafil 200mg ohne rezept
accutane ca azithromycin 250mg over the counter stromectol where to buy
clonidine 0.1mg oral generic catapres 0.1mg purchase tiotropium bromide
buspirone 5mg drug purchase buspar online order oxybutynin for sale
order hytrin 5mg generic order actos 15mg generic purchase sulfasalazine for sale
order olmesartan generic cost olmesartan 20mg diamox 250 mg pill
prograf price order tacrolimus for sale order urso 300mg online cheap
order bupropion 150mg without prescription order bupropion 150 mg generic buy quetiapine 100mg for sale
purchase molnupiravir generic naprosyn for sale online prevacid 15mg over the counter
brand salbutamol viagra 50mg pills for men sildenafil canada
cialis 10mg generic prozac 20mg cost order sildenafil 100mg generic
revia pills buy femara 2.5 mg generic abilify 20mg us
buy dapsone generic order allegra 180mg sale order perindopril 4mg sale
order fluvoxamine 100mg pill luvox 50mg pill order glucotrol generic
purchase piracetam online cheap buy viagra 100mg generic buy sildenafil pill
zithromax sale buy zithromax 250mg neurontin 800mg without prescription
rx pharmacy online cialis buy betamethasone 20gm creams buy anafranil for sale
order chloroquine 250mg for sale olumiant 4mg sale olumiant 2mg over the counter
glycomet brand tadalafil 5mg oral order cialis without prescription
metoprolol 50mg usa levitra order online levitra for sale
levitra ca buy methylprednisolone tablets buy methylprednisolone 16mg
help me write my research paper i need help with my assignment purchase viagra online
buy dapoxetine 30mg brand priligy 30mg purchase synthroid generic
orlistat canada diltiazem 180mg drug acyclovir 400mg drug
buy allopurinol 300mg pill buy rosuvastatin 10mg without prescription zetia pills
methotrexate 10mg usa buy coumadin 5mg generic buy reglan generic
cost motilium 10mg brand domperidone order flexeril 15mg sale
buy cozaar 50mg pill losartan 25mg ca topamax 200mg pills
buy imitrex 50mg online cheap buy sumatriptan 50mg online order dutasteride online cheap
order generic colchicine 0.5mg online casino usa blackjack online real money
tadalafil 20mg cheap ciprofloxacin oral oral ciprofloxacin 500mg
simvastatin ca order zocor sale propecia price
metronidazole 200mg brand clavulanate sale order bactrim pill
buy keflex 250mg pills erythromycin 250mg canada buy erythromycin 500mg pill
cialis 5mg without prescription buy viagra tablets sildenafil buy online
cheap cefuroxime 250mg order careprost pill purchase methocarbamol generic
casino online best online blackjack real money purchasing cialis on the internet
buy desyrel 100mg generic order trazodone 100mg sale aurogra 100mg for sale
academic writing services uk essay edit ivermectin 50 mg
sildenafil for men over 50 lamotrigine 50mg over the counter lamictal 200mg price
prednisone pills buy prednisone 5mg generic brand amoxicillin 1000mg
azithromycin over the counter cost gabapentin purchase gabapentin for sale
real casino games stromectol 3mg pill purchase provigil pills
order lasix pills order generic plaquenil order generic hydroxychloroquine 200mg
prednisone over the counter order mebendazole 100mg generic mebendazole 100mg generic
sildenafil 50mg tablet buy rhinocort online cheap rhinocort sale
buy tretinoin cream generic tretinoin cream oral buy avana 100mg sale