以一个 山寨 资源管理器 结束 file类与Directory类 (技术改变世界-cnblog)

文件与文件夹的处理,结束了,接下来的 啃的东西是 “流”

以一个 山寨 资源管理器 结束 file类与Directory类 (技术改变世界-cnblog)

View Code
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 Test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void btnSelect_Click(object sender, EventArgs e)
{

if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
txtPath.Text = folderBrowserDialog1.SelectedPath;
DirectoryInfo dir = new DirectoryInfo(txtPath.Text);
FileSystemInfo[] infos=dir.GetFileSystemInfos();
foreach (var info in infos)
{
if (info is DirectoryInfo)
{
DirectoryInfo i = new DirectoryInfo(info.FullName);
listView1.Items.Add(i.Name);
listView1.Items[listView1.Items.Count - 1].SubItems.Add(i.FullName);
listView1.Items[listView1.Items.Count - 1].SubItems.Add(i.CreationTime.ToShortDateString());

}
else
{
if (info is FileInfo)
{
FileInfo i = new FileInfo(info.FullName);
listView1.Items.Add(i.Name);
listView1.Items[listView1.Items.Count - 1].SubItems.Add(i.FullName);
listView1.Items[listView1.Items.Count - 1].SubItems.Add(i.CreationTime.ToShortDateString());

}
}
}
}

}

private void Form1_Load(object sender, EventArgs e)
{
txtPath.ReadOnly = true;
listView1.Columns.Add("文件名");
listView1.Columns.Add("路径");
listView1.Columns.Add("创建时间");

}
}
}



你可能感兴趣的:(Directory)