---
title: "遍历文件夹下的所有文件和子文件夹"
author: "berrywu"
date: "2010-04-23T11:39:41Z"
tags: []
categories: ["编程语言"]
slug: "untitled"
draft: false
lastmod: "2010-04-23T11:39:41Z"
id: 651107
url: "https://berrywu.iteye.com/blog/651107"
---

```
function my_scandir($dir)
{
     $files = array();
     if ( $handle = opendir($dir) ) {
         while ( ($file = readdir($handle)) !== false ) {
             if ( $file != ".." && $file != "." ) {
                 if ( is_dir($dir . "/" . $file) ) {
                     $files[$file] = scandir($dir . "/" . $file);
                 }else {
                     $files[] = $file;
                 }
             }
         }
         closedir($handle);
         return $files;
     }
} 

```