public static void FindFile(string dirPath) //参数dirPath为指定的目录
    {

        //在指定目录及子目录下查找文件,在listBox1中列出子目录及文件

        DirectoryInfo Dir = new DirectoryInfo(dirPath);

        try
        {

            foreach (DirectoryInfo d in Dir.GetDirectories()) //查找子目录
            {

                FindFile(Dir + d.ToString() + "\\");

                listBox1.Items.Add(Dir + d.ToString() + "\\"); //listBox1中填加目录名

                //leftMenu.Text += "<a href='" + Dir + d.ToString() + "\' onclick='return false'><img src='/admin/admin_images/fileicon.gif' width='40' border='0' />" + d.Name.ToString() + "</a>";

            }

            foreach (FileInfo f in Dir.GetFiles("*.jpg")) //查找文件
            {

                listBox1.Items.Add(Dir + f.ToString()); //listBox1中填加文件名

            }

        }

        catch (Exception e)
        {
            throw e;
        }

    }

相关文章: