码迷,mamicode.com
首页 > 其他好文 > 详细

遍历一个文件夹下的所有文件

时间:2016-08-14 07:12:48      阅读:133      评论:0      收藏:0      [点我收藏+]

标签:

一个老问题,但是总有人爱问,遍历一个文件夹下的所有文件,并输出文件信息。

 

using System;
using System.Collections.Generic;
using System.ComponentModel;using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

namespace IOTest
{
    public partial class Form1 : Form
    {
    
        private FolderBrowserDialog fbd;
        public Form1()
        {
            fbd = new FolderBrowserDialog();
            InitializeComponent();
        }

        private void btnOpen_Click(object sender, EventArgs e)
        {
            //选择路径
            fbd.ShowDialog();
            this.richTextBox1.Text ="open:"+ fbd.SelectedPath;
            //输出文件名
            PutOutName(fbd.SelectedPath);
        }

        private void PutOutName(string path)
        {
            foreach (string subPath in Directory.GetDirectories(path))
            {
                PutOutName(subPath);
            }
DirectoryInfo dir
= new DirectoryInfo(path); foreach (FileInfo file in dir.GetFiles()) { this.richTextBox1.AppendText("\n"+file.FullName+" size:"+file.Length.ToString()+" createTime:"+file.CreationTime.ToString()); } } } }

 

遍历一个文件夹下的所有文件

标签:

原文地址:http://www.cnblogs.com/longling2344/p/5769133.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!