找传奇、传世资源到传世资源站!

C# 文件夹管理实例源码下载

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

C# 文件夹管理实例源码下载 C#语言基础-第1张C# 文件夹管理实例源码下载 C#语言基础-第2张C# 文件夹管理实例源码下载 C#语言基础-第3张using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.IO;using System.Diagnostics;using System.Collections;using System.Threading;namespace FileManage{ public partial class frmMain : Form { #region 定义全局变量,并实例化公共类对象 private bool blCopy = false; //标识是否复制文件 private bool blCut = false; //标识是否剪切文件 public static string strFullName = ""; //记录选择的文件名及路径 public static ArrayList list = new ArrayList(); //记录选择的项 CommonClass.BaseClass baseclass = new FileManage.CommonClass.BaseClass(); #endregion public frmMain() { InitializeComponent(); } //窗体加载时在树控件中显示所有磁盘驱动器 private void frmMain_Load(object sender, EventArgs e) { MessageBox.Show("本软件涉及到对文件的各种操作,请在运行之前备份好您的磁盘文件,对于丢失文件的,我们不负任何法律责任!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); //获得本地磁盘的所有驱动器 string[] strDrives = Environment.GetLogicalDrives(); tvLook.BeginUpdate(); //向树控件中添加本地磁盘目录 foreach (string strDrive in strDrives) { TreeNode tnMyDrives = new TreeNode(strDrive); tvLook.Nodes.Add(tnMyDrives); } tvLook.EndUpdate(); } //在树控件中选择节点时,展开选中节点,并在右边显示该文件夹所包含的所有文件 private void tvLook_AfterSelect(object sender, TreeViewEventArgs e) { baseclass.GetPath(e.Node.FullPath, imageList1, lvInfo, 0); } //在指定目录下新建文件 private void 新建文件ToolStripMenuItem_Click(object sender, EventArgs e) { baseclass.NewFile(lvInfo, imageList1, DateTime.Now.ToString("yyyyMMddhhmmss") ".txt", 0); } //在指定目录下新建文件夹 private void 新建文件夹ToolStripMenuItem_Click(object sender, EventArgs e) { baseclass.NewFile(lvInfo, imageList1, DateTime.Now.ToString("yyyyMMddhhmmss"), 1); } //对指定文件夹中的内容进行全选 private void 全选ToolStripMenuItem_Click(object sender, EventArgs e) { for (int i = 0; i < lvInfo.Items.Count; i ) { lvInfo.Items[i].Selected = true; } tsslabInfo.Text = lvInfo.Items.Count "个对象"; } //复制文件及文件夹标识 private void 复制ToolStripMenuItem_Click(object sender, EventArgs e) { blCopy = true; 粘贴ToolStripMenuItem.Enabled = true; blCut = false; ISSelectFile(); } //剪切文件及文件夹标识 private void 剪切ToolStripMenuItem_Click(object sender, EventArgs e) { blCut = true; 粘贴ToolStripMenuItem.Enabled = true; blCopy = false; ISSelectFile(); } //根据复制或剪切文件及文件夹标识确定执行粘贴操作 private void 粘贴ToolStripMenuItem_Click(object sender, EventArgs e) { if (blCopy == true) { baseclass.CopyFile(lvInfo, imageList1, list, strFullName, CommonClass.BaseClass.AllPath, 0,toolStripProgressBar1); for (int i = 0; i < list.Count; i ) { baseclass.CopyDir(CommonClass.BaseClass.AllPath list[i].ToString(), strFullName list[i].ToString(), 0); } } else if (blCut == true) { baseclass.CopyFile(lvInfo, imageList1, list, strFullName, CommonClass.BaseClass.AllPath, 1, toolStripProgressBar1); for (int i = 0; i < list.Count; i ) { baseclass.CopyDir(CommonClass.BaseClass.AllPath list[i].ToString(), strFullName list[i].ToString(), 1); } blCut = false; 粘贴ToolStripMenuItem.Enabled = false; } else { MessageBox.Show("没有需要粘贴的内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } 刷新ToolStripMenuItem_Click(sender, e); toolStripProgressBar1.Value = 0; } //删除文件及文件夹 private void 删除ToolStripMenuItem_Click(object sender, EventArgs e) { try { baseclass.DeleteFile(lvInfo, imageList1, toolStripProgressBar1); toolStripProgressBar1.Value = 0; } catch (Exception ex) { MessageBox.Show(ex.Message); } } #region 重命名文件及文件夹 private void 重命名ToolStripMenuItem_Click(object sender, EventArgs e) { if (lvInfo.SelectedItems.Count != 0) { lvInfo.SelectedItems[0].BeginEdit(); } } private void lvInfo_AfterLabelEdit(object sender, LabelEditEventArgs e) { baseclass.RepeatFile(lvInfo, imageList1, lvInfo.SelectedItems[0].Text, e.Label); } //批量重命名文件 private void 批量重命名ToolStripMenuItem_Click(object sender, EventArgs e) { frmRepeat frmrepeat = new frmRepeat(); frmrepeat.ShowDialog(); } #endregion //刷新文件夹 private void 刷新ToolStripMenuItem_Click(object sender, EventArgs e) { baseclass.GetListViewItem(CommonClass.BaseClass.AllPath, imageList1, lvInfo); } //控制复制、剪切、删除、重命名菜单项的可用状态 private void lvInfo_Click(object sender, EventArgs e) { if (lvInfo.Items.Count > 0) { if (lvInfo.SelectedIndices.Count != 0) { 复制ToolStripMenuItem.Enabled = 剪切ToolStripMenuItem.Enabled = 删除ToolStripMenuItem.Enabled = 重命名ToolStripMenuItem.Enabled = true; tsslabInfo.Text = "选定" lvInfo.SelectedIndices.Count "个对象"; } } } #region 以各种方式显示文件 //以缩略图方式显示文件 private void 缩略图ToolStripMenuItem_Click(object sender, EventArgs e) { lvInfo.View = View.LargeIcon; 缩略图ToolStripMenuItem.Text =缩略图ToolStripMenuItem1.Text = "●缩略图"; 平铺ToolStripMenuItem.Text = 平铺ToolStripMenuItem1.Text = "平铺"; 图标ToolStripMenuItem.Text = 图标ToolStripMenuItem1.Text = "图标"; 列表ToolStripMenuItem.Text = 列表ToolStripMenuItem1.Text = "列表"; 详细信息ToolStripMenuItem.Text = 详细信息ToolStripMenuItem1.Text = "详细信息"; } private void 缩略图ToolStripMenuItem1_Click(object sender, EventArgs e) { 缩略图ToolStripMenuItem_Click(sender, e); } //以平铺方式显示文件 private void 平铺ToolStripMenuItem_Click(object sender, EventArgs e) { lvInfo.View = View.Tile; 缩略图ToolStripMenuItem.Text = 缩略图ToolStripMenuItem1.Text = "缩略图"; 平铺ToolStripMenuItem.Text = 平铺ToolStripMenuItem1.Text = "●平铺"; 图标ToolStripMenuItem.Text = 图标ToolStripMenuItem1.Text = "图标"; 列表ToolStripMenuItem.Text = 列表ToolStripMenuItem1.Text = "列表"; 详细信息ToolStripMenuItem.Text = 详细信息ToolStripMenuItem1.Text = "详细信息"; } private void 平铺ToolStripMenuItem1_Click(object sender, EventArgs e) { 平铺ToolStripMenuItem_Click(sender, e); } //以图标方式显示文件 private void 图标ToolStripMenuItem_Click(object sender, EventArgs e) { lvInfo.View = View.SmallIcon; 缩略图ToolStripMenuItem.Text = 缩略图ToolStripMenuItem1.Text = "缩略图"; 平铺ToolStripMenuItem.Text = 平铺ToolStripMenuItem1.Text = "平铺"; 图标ToolStripMenuItem.Text = 图标ToolStripMenuItem1.Text = "●图标"; 列表ToolStripMenuItem.Text = 列表ToolStripMenuItem1.Text = "列表"; 详细信息ToolStripMenuItem.Text = 详细信息ToolStripMenuItem1.Text = "详细信息"; } private void 图标ToolStripMenuItem1_Click(object sender, EventArgs e) { 图标ToolStripMenuItem_Click(sender, e); } //以列表方式显示文件 private void 列表ToolStripMenuItem_Click(object sender, EventArgs e) { lvInfo.View = View.List; 缩略图ToolStripMenuItem.Text = 缩略图ToolStripMenuItem1.Text = "缩略图"; 平铺ToolStripMenuItem.Text = 平铺ToolStripMenuItem1.Text = "平铺"; 图标ToolStripMenuItem.Text = 图标ToolStripMenuItem1.Text = "图标"; 列表ToolStripMenuItem.Text = 列表ToolStripMenuItem1.Text = "●列表"; 详细信息ToolStripMenuItem.Text = 详细信息ToolStripMenuItem1.Text = "详细信息"; } private void 列表ToolStripMenuItem1_Click(object sender, EventArgs e) { 列表ToolStripMenuItem_Click(sender, e); } //以详细信息方式显示文件 private void 详细信息ToolStripMenuItem_Click(object sender, EventArgs e) { lvInfo.View = View.Details; 缩略图ToolStripMenuItem.Text = 缩略图ToolStripMenuItem1.Text = "缩略图"; 平铺ToolStripMenuItem.Text = 平铺ToolStripMenuItem1.Text = "平铺"; 图标ToolStripMenuItem.Text = 图标ToolStripMenuItem1.Text = "图标"; 列表ToolStripMenuItem.Text = 列表ToolStripMenuItem1.Text = "列表"; 详细信息ToolStripMenuItem.Text = 详细信息ToolStripMenuItem1.Text = "●详细信息"; } private void 详细信息ToolStripMenuItem1_Click(object sender, EventArgs e) { 详细信息ToolStripMenuItem_Click(sender, e); } #endregion //双击ListView控件中的项进行打开 private void lvInfo_DoubleClick(object sender, EventArgs e) { baseclass.GetPath(lvInfo.SelectedItems[0].Text, imageList1, lvInfo, 1); } //返回上一级目录 private void tsbtnBack_Click(object sender, EventArgs e) { baseclass.backPath(lvInfo, imageList1); } //单击ListView控件的标头时,对项进行排序 private void lvInfo_ColumnClick(object sender, ColumnClickEventArgs e) { try { lvInfo.ListViewItemSorter = new CommonClass.ListViewItemComparer(e.Column); } catch { } } #region 搜索文件或文件夹 //搜索文件或文件夹 private void tsbtnSearch_Click(object sender, EventArgs e) { lvInfo.Items.Clear(); if (ttxtKeyWord.Text != "") { baseclass.SearchFile(lvInfo, ttxtKeyWord.Text); } else { MessageBox.Show("搜索关键字不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); 刷新ToolStripMenuItem_Click(sender, e); } toolStripProgressBar1.Value = 0; } //在搜索关键字文本框中按下回车键时,执行搜索文件或文件夹操作 private void ttxtKeyWord_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == 13) { tsbtnSearch_Click(sender, e); } } #endregion #region 退出当前应用程序 //单击“关闭”菜单项 private void 关闭ToolStripMenuItem_Click(object sender, EventArgs e) { Application.Exit(); } //单击“*”按钮 private void frmMain_FormClosing(object sender, FormClosingEventArgs e) { 关闭ToolStripMenuItem_Click(sender, e); } #endregion //监视对象选中状态 private void timer1_Tick(object sender, EventArgs e) { if (lvInfo.SelectedIndices.Count != 0) { tsslabInfo.Text = "选定" lvInfo.SelectedIndices.Count "个对象"; list = baseclass.getFiles(lvInfo); } else tsslabInfo.Text = lvInfo.Items.Count "个对象"; } //弹出“关于”对话框 private void 关于文件批量处理器ToolStripMenuItem_Click(object sender, EventArgs e) { AboutBox aboutbox = new AboutBox(); aboutbox.ShowDialog(); } #region 解压缩文件 //压缩文件及文件夹 private void 压缩文件ToolStripMenuItem_Click(object sender, EventArgs e) { try { if (saveFileDialog.ShowDialog() == DialogResult.OK) { toolStripProgressBar1.Maximum = list.Count; if (list.Count > 1) { string strNewPath = DateTime.Now.ToString("yyyyMMddhhmmss"); baseclass.CopyFile(lvInfo, imageList1, list, CommonClass.BaseClass.AllPath, CommonClass.BaseClass.AllPath strNewPath "\\", 0, toolStripProgressBar1); for (int i = 0; i < list.Count; i ) { baseclass.CopyDir(CommonClass.BaseClass.AllPath strNewPath "\\" list[i].ToString(), CommonClass.BaseClass.AllPath list[i].ToString(), 0); if (toolStripProgressBar1.Value < toolStripProgressBar1.Maximum) toolStripProgressBar1.Value = 1; } baseclass.Zip(strNewPath, saveFileDialog.FileName); Directory.Delete(CommonClass.BaseClass.AllPath strNewPath, true); MessageBox.Show("压缩文件成功"); } else if (lvInfo.SelectedIndices.Count > 0) { baseclass.Zip(lvInfo.SelectedItems[0].Text, saveFileDialog.FileName); MessageBox.Show("压缩文件成功"); } 刷新ToolStripMenuItem_Click(sender, e); toolStripProgressBar1.Value = 0; } } catch { } } //解压文件 private void 解压文件ToolStripMenuItem_Click(object sender, EventArgs e) { try { folderBrowserDialog.ShowDialog(); if (lvInfo.SelectedIndices.Count > 0) { FileInfo FInfo = new FileInfo(CommonClass.BaseClass.AllPath lvInfo.SelectedItems[0].Text); if (FInfo.Exists && (FInfo.Extension.ToLower() == ".rar" || FInfo.Extension.ToLower() == ".zip")) { baseclass.UnZip(lvInfo.SelectedItems[0].Text, folderBrowserDialog.SelectedPath); MessageBox.Show("解压文件成功"); } } } catch { } } #endregion //分割文件,打开“分割文件”窗体 private void 文件分割ToolStripMenuItem_Click(object sender, EventArgs e) { frmSplit frmsplit = new frmSplit(); frmsplit.tabControl1.SelectedIndex = 0; frmsplit.ShowDialog(); } //合成文件,打开“合成文件”窗体 private void 文件合成ToolStripMenuItem_Click(object sender, EventArgs e) { frmSplit frmsplit = new frmSplit(); frmsplit.tabControl1.SelectedIndex = 1; frmsplit.ShowDialog(); } //清除系统垃圾文件 private void 垃圾文件清理ToolStripMenuItem_Click(object sender, EventArgs e) { try { System.Diagnostics.Process.Start(Application.StartupPath "\\clear.bat"); } catch { } } #region 判断是否选择了文件 /// <summary> /// 判断是否选择了文件 /// </summary> private void ISSelectFile() { if (lvInfo.SelectedIndices.Count == 0) { MessageBox.Show("请选择文件", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); 复制ToolStripMenuItem.Enabled = 剪切ToolStripMenuItem.Enabled = 删除ToolStripMenuItem.Enabled = 重命名ToolStripMenuItem.Enabled = false; } else { strFullName = CommonClass.BaseClass.AllPath; list = baseclass.getFiles(lvInfo); } } #endregion }}

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复