PHP Traverse files directory and purge files in directory

Source: Internet
Author: User
Today bored practice a bit of PHP traversal file directory program, wrote the following two programs, but the quality is not very good, Pat ~ ~ ~

1. Clear the PHP cache file

<?phpfunction Read_dir ($dir, $file) {$a =strpos ($file, ". php"), if ($a >0) {unlink ($dir. $file); echo "Delete $dir $ File <br> "; return true;} if (Strpos ($file, ".") = = = 0 | | Strpos ($file, ".")! = = False) return True;if (Strpos ($file, ".") = = = False | | Strpos ($dir, "/") = = = False) {$dir = $dir. $file. "/"; if (!is_dir ($dir)) return false; $dh = Opendir ($dir); while (($file = Readdir ($DH) = = False) {Read_dir ($dir, $file);   Recursive call}}}function clear_caches () {$dir = "./temp/";  The PHP cache file directory to be purged if (!is_dir ($dir)) Die ("It was not a dir"), $dh = Opendir ($dir), while (($file = Readdir ($DH))!=false) {//var_ Dump ($file); Read_dir ($dir, $file);}}? >
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.