帮忙把一下代码改成控制台咯,多谢了 。。。
我一窍不通 、
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Threading;
using System.Data.SqlClient;
using System.IO;
using System.Windows.Forms;
using System.Net;
using System.Collections;
namespace WindowsGetTree
{
public partial class Form3 : Form
{
List<FileInfoEx> list = new List<FileInfoEx>();
public Form3()
{
InitializeComponent();
LoadFileList(@"D:\Demo\backupdir");
for (int i = 0; i < list.Count; i++)
{
this.richTextBox1.Text += list[i].ToString() + "\r\n";
}
DateTime maxdate = DateTime.Now.AddYears(-20);
for (int i = 0; i < list.Count; i++)
{
if (maxdate < list[i].date)
maxdate = list[i].date;
}
DateTime PaTime = maxdate.AddDays(-20);
long sum = 0;
for (int i = 0; i < list.Count; i++)
{
if (PaTime < list[i].date)
{
sum += list[i].size;
}
}
this.textBox1.Text = sum.ToString()+"KB";
}
private void Form3_Load(object sender, EventArgs e)
{
}
public void LoadFileList(string dir)
{
foreach (String directoryPath in Directory.GetDirectories(dir))
{
LoadFileList(directoryPath);
}
foreach (String filename in Directory.GetFiles(dir))
{
FileInfo fi = new FileInfo(filename);
FileInfoEx fiex = new FileInfoEx();
fiex.filename = filename;
fiex.date = fi.LastWriteTime;
fiex.size = fi.Length;
list.Add(fiex);
}
}
}
public class FileInfoEx
{
public string filename;
public DateTime date;
public long size;
public override string ToString()
{
return filename + " - " + date + " - " + size;
}
}
}
转成控制台作什么用呢?
如果只是演示,还不如用dir /p
工具:CMD/PowerShell
如果是学习,你只要把
this.richTextBox1.Text += list[i].ToString() + "\r\n";
//*****
this.textBox1.Text += sum.ToString()+"KB";
转成:
Console.WriteLine( list[i].ToString() + "\r\n");
//****
Console.WriteLine(sum.ToString() + "KB");
就可以了啊!
可以参考上次写过的实例
http://space.cnblogs.com/question/9527/