zoukankan      html  css  js  c++  java
  • 小型资源管理器

     1   public class MyFile
     2     {//文件长度
     3         private float fileLength;
     4 
     5         public float FileLength
     6         {
     7             get { return fileLength; }
     8             set { fileLength = value; }
     9         }
    10         //文件名
    11         private string filrName;
    12 
    13         public string FilrName
    14         {
    15             get { return filrName; }
    16             set { filrName = value; }
    17         }
    18         //文件路径
    19         private string filePath;
    20 
    21         public string FilePath
    22         {
    23             get { return filePath; }
    24             set { filePath = value; }
    25         }
    26         //文件类型
    27         private string fileType;
    28 
    29         public string FileType
    30         {
    31             get { return fileType; }
    32             set { fileType = value; }
    33         }
    34     }

     1  private void Form1_Load(object sender, EventArgs e)
     2         {
     3             //添加根节点
     4             TreeNode nodeRoot = new TreeNode();
     5             nodeRoot.Text = "D://";
     6             nodeRoot.Tag = "D://";
     7             tvDirectory.Nodes.Add(nodeRoot);
     8         }
     9        
    10 
    11         private void BindInfo(TreeNode node)
    12         {
    13             throw new NotImplementedException();
    14         }
    15 
    16        
    17 
    18         private void tsmiCopy_Click(object sender, EventArgs e)
    19         {
    20             if (lvFile.SelectedItems.Count > 0)
    21             {
    22                 //浏览文件夹中的对话框
    23                 FolderBrowserDialog fbd = new FolderBrowserDialog();
    24                 DialogResult result = fbd.ShowDialog();
    25                 //判断用户是否点了确定
    26                 if (result == DialogResult.OK)
    27                 {
    28                     string path1 = lvFile.SelectedItems[0].SubItems[3].Text;
    29                     string path = fbd.SelectedPath + "//" + lvFile.SelectedItems[0].Text;//文件夹+文件名
    30                     File.Copy(path1, path, true);//复制文件
    31                     MessageBox.Show("文件复制成功");
    32                 }
    33             }
    34             else
    35             {
    36                 MessageBox.Show("请选择要复制的文件");
    37             }
    38         }
    39 
    40       
    41         private void tvDirectory_AfterSelect(object sender, TreeViewEventArgs e)
    42         {
    43             TreeNode node = tvDirectory.SelectedNode;
    44             string tag = node.Tag.ToString();
    45             //创建目录对象
    46             DirectoryInfo di = new DirectoryInfo(tag);
    47             DirectoryInfo[] dirs = di.GetDirectories();
    48             node.Nodes.Clear();
    49             //循环绑定数据到TreeView中
    50             foreach (DirectoryInfo d in dirs)
    51             {
    52                 TreeNode node2 = new TreeNode();
    53                 node2.Text = d.Name;
    54                 node2.Tag = d.FullName;
    55                 node.Nodes.Add(node2);//把节点添加到当前选中的节点
    56             }
    57             //得到当前目录下的子文件
    58             FileInfo[] files = di.GetFiles();
    59             //清空原有数据
    60             lvFile.Items.Clear();
    61             //循环绑定数据到ListView中
    62             foreach (FileInfo fi in files)
    63             {
    64                 ListViewItem lvi = new ListViewItem();
    65                 lvi.Text = fi.Name;//文件名
    66                 lvi.SubItems.Add(fi.Extension.Substring(1));//类型
    67                 lvi.SubItems.Add((fi.Length / 1024.0).ToString());//大小
    68                 lvi.SubItems.Add(fi.FullName);//完整路径
    69                 lvFile.Items.Add(lvi);
    70             }
    71 
    72         }
    73 
    74         private void lvFile_SelectedIndexChanged(object sender, EventArgs e)
    75         {
    76             if (lvFile.SelectedItems.Count > 0)
    77             {
    78                 DialogResult result = MessageBox.Show("确定要删除嘛", "提示",
    79                   MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
    80                 if (result == DialogResult.OK)
    81                 {
    82                     string path = lvFile.SelectedItems[0].SubItems[3].Text;
    83                     File.Delete(path);//删除文件
    84                     MessageBox.Show("删除成功");
    85                 }
    86             }
    87             else
    88             {
    89                 MessageBox.Show("请选择删除的文件");
    90             }
    91         }
  • 相关阅读:
    C#基础知识——类的继承
    值传递与引用传递01
    今天接到任务了!
    傅立叶变换,时域,频域二
    傅立叶变换,时域,频域一
    常用运放选型一览表
    用三段140字符以内的代码生成一张1024×1024的图片
    [收藏夹整理]电子类链接
    [收藏夹整理]三维重构部分
    MSP430之自动增益程控放大main备份
  • 原文地址:https://www.cnblogs.com/aaaaliling/p/8903731.html
Copyright © 2011-2022 走看看