Home  >  Article  >  Backend Development  >  php删除同目录下所有txt文件解决方案

php删除同目录下所有txt文件解决方案

WBOY
WBOYOriginal
2016-06-13 10:13:02889browse

php删除同目录下所有txt文件
这个语句怎么写?

------解决方案--------------------
先遍历该文件夹,然后用pathinfo判断扩展名,然后unlink
------解决方案--------------------
foreach(glob('目录名/*.txt') as $f)
unlink($f);
------解决方案--------------------

PHP code
 $files=glob("*.txt"); foreach($files as $file)   unlink($file);<br><font color="#e78608">------解决方案--------------------</font><br>
PHP code
$files=glob("*.txt"); foreach($files as $file)   if(is_file($file)### dir1/dir2/dir3.txt/     unlink($file);<br><font color="#e78608">------解决方案--------------------</font><br>当你了解php有一个函数:glob()之后,您就知道这个问题如何处理了。<br>glog()用法详解:http://www.e2003.net/html/article-2984.html<br><div class="clear">
                 
              
              
        
            </div>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn