Heim >Backend-Entwicklung >PHP-Tutorial >php删除文件夹下的所有文件

php删除文件夹下的所有文件

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-20 12:34:421038Durchsuche

直接上代码

   public function delpath($path){       if($handle=opendir($path)){                 while(false!==($file=readdir($handle))){                     if ($file != "." && $file != "..") {                         @unlink($path."".$file);                     }                 }             }           }

其实主要的思路就是,首先获取文件夹下的所有文件,并将其遍历出来,当然我这个是在项目中已经提前知道我这个是文件,不是文件夹。在遍历的同时再进行一一删除。

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn