首页 新闻 赞助 找找看

一个winform转换成控制台的问题 ?

0
悬赏园豆:10 [已解决问题] 解决于 2009-09-24 09:51

帮忙把一下代码改成控制台咯,多谢了 。。。

我一窍不通 、

 

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;
        }
    }

}

Yellows的主页 Yellows | 初学一级 | 园豆:45
提问于:2009-09-24 09:22
< >
分享
最佳答案
0

转成控制台作什么用呢?

如果只是演示,还不如用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/

收获园豆:10
邀月 | 高人七级 |园豆:25475 | 2009-09-24 09:37
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册