分享

c#程序显示所选目录及其子目录内所有文件...

 thy 2009-04-03
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Collections;
using System.Drawing;
using System.Text;
using System.IO;
using System.Windows.Forms;
namespace formTest
{
    public partial class Form3 : Form
    {
        SCItemSet itemSet = new SCItemSet();
        public Form3()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.Run(new Form3());
        }
        private void btnBrowse_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog browse = new FolderBrowserDialog();
            browse.ShowDialog();           
            txtShowPath.Text = browse.SelectedPath;
        }
        private void detail_Click(object sender, EventArgs e)
        {
            txtShowDetail.Text = string.Empty;
            string ShowInfo="";
            //string ShowPath = txtShowPath.Text.ToString().Replace("\\", @"\");
            getDirFiles(txtShowPath.Text);
            for(int i=0;i<itemSet.Count;i++)
            {
                ShowInfo += itemSet[i].Name+"\r\n";
            }
            txtShowDetail.Text = ShowInfo.ToString(); 
        }
        public void getDirFiles(string strPaths)
        {
            DirectoryInfo d = new DirectoryInfo(strPaths);
           
            DirectoryInfo[] dis = d.GetDirectories();
            FileInfo[] fis = d.GetFiles();
            foreach (FileInfo fi in fis)
            {
                SCItem item = new SCItem();
                item.Name = fi.Name;
                itemSet.Add(item);
            }
            string strPath;
            foreach (DirectoryInfo di in dis)
            {  
                strPath=strPaths+"\\"+di.Name;
                getDirFiles(strPath);
            }
           
        } 
   }   
}
 

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多