c#做的资源管理器

private void button2_Click(object sender, EventArgs e)
        {
            DirDG(treeView1.Nodes.Add(@"F:/我的项目", "我的项目"));
        }
 //以节点的形式获取的所有目录文件
        void DirDG(TreeNode tn)
        {
            try
            {
                foreach (string str in Directory.GetDirectories(tn.Name))
                {
                    DirDG(tn.Nodes.Add(str, Path.GetFileNameWithoutExtension(str)));
                }
            }
            catch
            { }

        }

        private void button3_Click(object sender, EventArgs e)
        {
            listView1.Items.Clear();
  //遍历节点下的文件得到名称添加到ListViewItem 中
            foreach (string str in Directory.GetDirectories

(treeView1.SelectedNode.Name))
            {
                ListViewItem lvi = listView1.Items.Add(str,

Path.GetFileNameWithoutExtension(str), 0);
//获得详细信息的列表
                lvi.SubItems.Add(Directory.GetLastWriteTime(str).ToString("yyyy年MM

月dd日"));
                lvi.SubItems.Add("文件夹");
                lvi.SubItems.Add(GetSize(str).ToString());


            }
  //得到所有的文件
            foreach (string str in Directory.GetFiles(treeView1.SelectedNode.Name))
            {
                ListViewItem lvi = listView1.Items.Add(str, Path.GetFileName(str),

0);
                lvi.SubItems.Add(File.GetLastWriteTime(str).ToString("yyyy年MM月dd日

"));
                lvi.SubItems.Add(Path.GetExtension(str));
                lvi.SubItems.Add(new FileInfo(str).Length.ToString());


            }


        }
 //获取文件的大小
        long GetSize(string path)
        {
            long len = 0;
            foreach (string str in Directory.GetDirectories(path))
            {
                len = GetSize(str);
            }
            long Len = 0;
            foreach (string str in Directory.GetFiles(path))
            {
                FileInfo fi = new FileInfo(str);
                Len += fi.Length;
            }
            return Len + len;
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            listView1.View = (View)Enum.Parse(typeof(View),

comboBox1.SelectedItem.ToString());
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            comboBox1.DataSource = Enum.GetNames(typeof(View));
        }

        private void listView1_Click(object sender, EventArgs e)
        {

        }

        private void listView1_DoubleClick(object sender, EventArgs e)
        {
            string path = listView1.SelectedItems[0].Name;
            if (!Path.HasExtension(path))
            {
                listView1.Items.Clear();
                foreach (string str in Directory.GetDirectories(path))
                {
                    ListViewItem lvi = listView1.Items.Add(str,

Path.GetFileNameWithoutExtension(str), 0);
                    lvi.SubItems.Add(Directory.GetLastWriteTime(str).ToString("yyyy

年MM月dd日"));
                    lvi.SubItems.Add("文件夹");
                    lvi.SubItems.Add(GetSize(str).ToString());
                }
            }
            else
            {//带扩展名的直接打开文件
                Process.Start(path);
            }
        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值