C# 小型资源管理器


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace 小型资源管理器
{
public class MyFile
{
public float FileLength { get; set; }//文件长度(KB)
public string FileName { get; set; }//文件名
public string FilePath { get; set; }//文件路径
public string FileType { get; set; }//文件类型
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO; namespace 小型资源管理器
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
TreeNode tn;
private void Form1_Load(object sender, EventArgs e)
{
//检索计算机上的所有逻辑驱动器的驱动器名称。
DriveInfo[] di = DriveInfo.GetDrives();
foreach (DriveInfo item in di)
{
tn = new TreeNode(item.Name);
tn.Tag = item.Name;
tv01.Nodes.Add(tn);
}
} //单击绑定文件和文件夹信息
private void tv01_AfterSelect(object sender, TreeViewEventArgs e)
{
TreeNode tn= tv01.SelectedNode;
BingInfo(tn); } private void BingInfo(TreeNode tn)
{
//清空
lvlist.Items.Clear();
//绑定子目录
DirectoryInfo dic = new DirectoryInfo(tn.Tag.ToString());
DirectoryInfo[] info = dic.GetDirectories();
foreach (DirectoryInfo item in info)
{
TreeNode temp = new TreeNode();
temp.Text = item.Name;
temp.Tag = item.FullName;
tn.Nodes.Add(temp);
} //获取目录下文件列表
FileInfo[] fileinfo = dic.GetFiles();
//定义泛型集合存储文件信息
List<MyFile> files = new List<MyFile>();
//遍历文件列表
foreach (FileInfo it in fileinfo )
{ MyFile file = new MyFile();
file.FileName = it.Name;
file.FileLength = it.Length;
file.FileType = it.Extension;
file.FilePath = it.FullName;
files.Add(file);
}
//绑定到listview中
foreach (MyFile em in files )
{
ListViewItem lv = new ListViewItem(em.FileName );
lv.SubItems.Add(em.FileLength.ToString () );
lv.SubItems.Add(em.FileType );
lv.SubItems.Add(em.FilePath );
lvlist.Items.Add(lv);
} } //复制
private void 复制ToolStripMenuItem_Click(object sender, EventArgs e)
{
//判断是否选中
if (lvlist .SelectedItems .Count ==)
{
return;
}
//提示用户选择目标文件夹
FolderBrowserDialog fbd = new FolderBrowserDialog();
DialogResult result = fbd.ShowDialog();
//源文件路径
string sourcepath = lvlist.SelectedItems[].SubItems[].Text;
//目标文件路径
string despath = null;
//如果正确选择目标位置,执行复制操作
if (result==DialogResult .OK )
{
despath = fbd.SelectedPath;
//lvlist表示显示文件信息的ListView对象
despath += "\\" + lvlist.SelectedItems[].SubItems[].Text;
//复制文件
File.Copy(sourcepath ,despath );
MessageBox.Show("复制成功!");
} } //删除
private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
{ string delectpath= lvlist.SelectedItems[].SubItems [].Text ;
File.Delete(delectpath);
MessageBox.Show("删除成功!");
} }
}
C# 小型资源管理器的更多相关文章
- 初识IO流之小型资源管理器
初次接触到IO流,根据书本上的知识,加上自己的摸索,发现了一些好玩的事情.(书本上的知识或多或少,有时候不足以解决我们的问题!这时候我们就应该自己去求解!!! 所以我们学习的时候要抱有探索的精神,求知 ...
- IO流的应用————小型资源管理器
小型资源管理器 private void LoadTreeView() { DirectoryInfo dir = new DirectoryInfo(@"E:\"); Direc ...
- 实现1.双击自动关联文件类型打开 2.PC所有驱动器 3.小型资源管理器
感谢各位这里实现:双击自动关联文件类型打开 2.PC所有驱动器 3.小型资源管理器!! 首先主页面: 2.运用DriveInfo驱动器的信息:获得整个系统磁盘驱动!!,运用frorach循环遍历到Tr ...
- 小型资源管理器,IO操作,读取和写入文件和目录的常用操作
解决方案: 小总结: 用IO流,的file,DirectoryInfo的方法绑定Treeview控件上和删除,读取, 可以熟练掌握一下IO流 主页面: private void Form1_Load( ...
- 小型资源管理器之动态添加TreeView节点
FrmMain主界面 using System; using System.Collections.Generic; using System.ComponentModel; using System ...
- 360安全卫士造成Sharepoint文档库”使用资源管理器打开“异常
备注:企业用户还是少用360为妙 有客户反馈:部门里的XP SP2环境客户机全部异常,使用资源管理器打开Sharepoint文档库,看到的界面样式很老土,跟本地文件夹不一样 ...
- Windows 7 在资源管理器中显示软件快捷方式
该方法是利用资源管理器中储存网络位置的文件夹实现的, 不需要修改注册表. 效果如图: 操作方法: 在资源管理器中打开路径 "%appdata%\Microsoft\Windows\Netwo ...
- 修复 Windows7 资源管理器左侧收藏夹无法展开问题
相信大家在网上搜多到的解决办法大多数都是修改注册表,但是这个办法多数是无效的 1.运行regedit 2.展开到HKEY_CLASSES_ROOT\lnkfile 3.添加一个字符串值:IsShort ...
- [No00009C]Visual Studio在 解决方案资源管理器 里同步定位打开的文件
标题的意思就是在使用VS的时候,需要我们打开编辑的文件跟解决方案的资源管理器同步显示,这样方便定位到我们在修改哪个文件. 设置如下: 工具——选项——项目和解决方案——在解决方案资源管理器中跟踪活动项 ...
随机推荐
- javascript-this,call,apply,bind简述3
上节介绍了call()和apply()的用法,这节再讨论一下arguments参数和bind函数的用法以及函数柯里化就算是完结了. bind()函数 先看定义: bind()方法会创建一个函数的实例, ...
- SAP和Java系统的Webservice实例
简介: 关于Webservice的概念和原理,简单来讲,Webservice是一种基于SOAP传输协议,用WSDL描述,用XML封装数据的接口技术.由于其跨平台.跨防火墙.开发成本低.开发周期短等优势 ...
- 404 & 401 Errors with the App Management Service
from:http://blogs.technet.com/b/sharepoint_-_inside_the_lines/archive/2013/06/23/404-amp-401-errors- ...
- 如何通过PowerShell在Visual Studio的Post-build中预热SharePoint站点
问题现象 Visual Studio在开发SharePoint的时候,发布部署包后,首次打开及调试站点页面的时候会非常的慢 解决方案 使用PowerShell脚本,加载SharePoint插件后遍历所 ...
- iOS8以后 UISearchController的用法
查了不少资料,都不太全,自己查看了apple文档,写了一份代码: 如下(只是界面): 1. 声明属性 @property (nonatomic, strong) UISearchController ...
- iOS 修改label中文字的行间距
UILabel *label = [[UILabel alloc] init]; label.font = [UIFont systemFontOfSize:]; label.textColor = ...
- apt-cache, apt-get
apt是debian系的软件包的管理工具,他们可以通过搜索在/var/lib/apt/list里的索引文件搜做根据/etc/apt/sources.list里的软件源来在线安装软件,安装的过程还可以自 ...
- javascript 特效实现(2)——回到顶部效果
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- UVA 11355 Cool Points(几何)
Cool Points We have a circle of radius R and several line segments situated within the circumference ...
- td内元素居顶,td元素不随高度的撑开而变位置
如下图,右边内容变高了,左边元素位置就下降到居中 设置居顶不变的方法 <table width="200" border="1"> <tr&g ...