zoukankan      html  css  js  c++  java
  • IO流的应用————小型资源管理器

    小型资源管理器

        

           

    private void LoadTreeView()
    {
      DirectoryInfo dir = new DirectoryInfo(@"E:");
      DirectoryInfo[] dirs= dir.GetDirectories();
      foreach (DirectoryInfo item in dirs)
      {
        TreeNode tn = new TreeNode();
        tn.Text = item.Name;
        tn.Tag = item.FullName;
        this.treeView1.Nodes.Add(tn);
      }

    }
    private void Form1_Load(object sender, EventArgs e)
    {
      LoadTreeView();

    }
    private void BindInfo(TreeNode node)
    {
      DirectoryInfo dir = new DirectoryInfo(node.Tag.ToString());
      DirectoryInfo[] dirs = dir.GetDirectories();
      foreach (DirectoryInfo item in dirs)
      {
        TreeNode tn = new TreeNode();
        tn.Text = item.Name;
        tn.Tag = item.FullName;
        node.Nodes.Add(tn);
      }
      FileInfo[] fileInfo = dir.GetFiles();
      List<MyFile> files = new List<MyFile>();
      foreach (FileInfo item in fileInfo)
      {
        MyFile file = new MyFile();
        file.FileName = item.Name;
        float value = item.Length;
        file.FileLength = float.Parse(Math.Round(value / 1024, 2).ToString());
        file.FileType = item.Extension;
        file.FilePath = item.FullName;
        files.Add(file);
      }
      if (this.listView1.Items!=null)
      {
        this.listView1.Items.Clear();
      }
      foreach (MyFile item in files)
      {
        ListViewItem lvItem = new ListViewItem(item.FileName);
        lvItem.SubItems.Add(item.FileLength.ToString());
        lvItem.SubItems.Add(item.FileType);
        lvItem.SubItems.Add(item.FilePath);
        this.listView1.Items.Add(lvItem);
      }
    }

    private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
    {

        TreeNode node = this.treeView1.SelectedNode;
        BindInfo(node);

    }

    private void 复制ToolStripMenuItem_Click(object sender, EventArgs e)
    {
      DialogResult result= folderBrowserDialog1.ShowDialog();
      if (result==DialogResult.OK)
      {
        string sourcePath = this.listView1.SelectedItems[0].SubItems[3].Text;
        string desPath = folderBrowserDialog1.SelectedPath;
        desPath += "\" + this.listView1.SelectedItems[0].SubItems[0].Text;
        File.Copy(sourcePath, desPath);
        MessageBox.Show("复制成功!!!");
      }
    }

    private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
    {
        string sourcePath = this.listView1.SelectedItems[0].SubItems[3].Text;
        File.Delete(sourcePath);
        MessageBox.Show("删除成功!!");
        TreeNode node = this.treeView1.SelectedNode;
        BindInfo(node);
    }

  • 相关阅读:
    图形界面 Fedora Core 12/Core 11 How to log in GUI as r
    nis_client.txt
    nis_server.txt
    passwd
    samba.set
    【22.48%】【codeforces 689D】Friends and Subsequences
    【71.76%】【codeforces 732A】Buy a Shovel
    【56.74%】【codeforces 732B】Cormen --- The Best Friend Of a Man
    【43.26%】【codeforces 732C】Sanatorium
    【37.50%】【codeforces 732D】Exams
  • 原文地址:https://www.cnblogs.com/PGYXZ/p/4655939.html
Copyright © 2011-2022 走看看