基本信息
源码名称:C# 获取文件列表以及遍历文件夹
源码大小:0.05M
文件格式:.rar
开发语言:C#
更新时间:2018-03-20
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace getFilelist
{
    public partial class FrmLstFile : Form
    {
        public FrmLstFile()
        {
            InitializeComponent();
        }

        private void btnBrowse_Click(object sender, EventArgs e)
        {
            //folderBrowserDialog1.SelectedPath=this.           
            string defaultPath = "";
            FolderBrowserDialog dialog = new FolderBrowserDialog();
            //打开的文件夹浏览对话框上的描述
            dialog.Description = "请选择一个文件夹";
            //是否显示对话框左下角 新建文件夹 按钮,默认为 true
            dialog.ShowNewFolderButton = false;

            //首次defaultPath为空,按FolderBrowserDialog默认设置(即桌面)选择
            if (defaultPath != "")
            {
                //设置此次默认目录为上一次选中目录
                dialog.SelectedPath = defaultPath;
            }
            //按下确定选择的按钮
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                //记录选中的目录
                defaultPath = dialog.SelectedPath;
            }
            textBox1.Text = defaultPath;
            //MessageBox.show(defaultPath);
        }

        private void btnList_Click(object sender, EventArgs e)
        {
            string FileDir = textBox1.Text;
            List<getFilelist.Class1.FileInformation> list = getFilelist.Class1.DirectoryAllFiles.GetAllFiles(new System.IO.DirectoryInfo(@FileDir));
            //if (list.Where(t => t.FileName.ToLower().Contains("android")).Any())                 
           
                //Console.WriteLine("true");

            foreach (var item in list)
            {
                FileInfo fi = new FileInfo(item.FilePath);
                lstFolder.Items.Add(item.FilePath);
                if (fi.LastWriteTime.ToShortDateString() == dateTP.Value.ToShortDateString()) // DateTime.Now.ToShortDateString())
                {
                    lstFile.Items.Add(item.FilePath);
                    //lstFolder.Items.Add(item.FilePath);
                    //lstFile.Items.Add(item.FileName);
                }
                //Console.WriteLine(string.Format("文件名:{0}---文件目录{1}", item.FileName, item.FilePath));
            }
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }
       
        private void lstFolder_SelectedIndexChanged(object sender, EventArgs e)
        {
            //DirectoryInfo dir = new DirectoryInfo(lstFolder.Text);
            //foreach (FileInfo NextFile in dir.GetFiles())
            //    this.lstFile.Items.Add(NextFile.Name);
        }

        void getAllFiles(string path)
        { 
            var files = Directory.GetFiles(path, "*.*");

            foreach (var file in files)
            {
                this.lstFile.Items.Add(file);
                //Console.WriteLine(file);
            }
        }

       


    }
}