这是我的代码,不知道以后的怎么做了,请大家赐教.谢谢!
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;
namespace Compress
{
public partial class FormFile : Form
{
public FormFile()
{
InitializeComponent();
}
private DirectoryInfo folder;
private void FormFile_Load(object sender, EventArgs e)
{
LoadTree();
}
private void LoadTree()
{
DirectoryInfo directory;
//clear the tree
//treeExplore.Nodes.Clear();
//Loop through the drive letter and find the available drive
foreach (string drive in Environment.GetLogicalDrives())
{
try
{
// get the directory information for this path
directory = new DirectoryInfo(drive);
//if the retrived directory is valid ,add it to the tree view
if (directory.Exists == true)
{
TreeNode newNode = new TreeNode(directory.FullName);
treeExplore.Nodes.Add(newNode);
//add the new node to the root level
GetSubDirectories(newNode);
}
}
catch
{
return;
}
}
}
private void GetSubDirectories(TreeNode parent)
{
DirectoryInfo directory;
try
{
//check if we have already scanned this folder
if (parent.Nodes.Count == 0)
{
directory = new DirectoryInfo(parent.FullPath);
foreach (DirectoryInfo dir in directory.GetDirectories())
{
TreeNode newNode = new TreeNode(dir.Name);
parent.Nodes.Add(newNode);
}
}
//Scan the frist level of sub folder to creat + or - sign
foreach (TreeNode node in parent.Nodes)
{
//if we have scanned this code before
if (node.Nodes.Count == 0)
{
//get the folder information for the special path
directory = new DirectoryInfo(node.FullPath);
foreach (DirectoryInfo dir in directory.GetDirectories())
{
//create a new node to add it to the tree
TreeNode newNode = new TreeNode(dir.Name);
node.Nodes.Add(newNode);
}
}
}
}
catch
{
return;
}
}
private void treeExplore_AfterSelect(object sender, TreeViewEventArgs e)
{
DirectoryInfo dirInfo = new DirectoryInfo(e.Node.FullPath);
listExplorer.Items.Clear();
if (dirInfo.Exists)
{
FileInfo[] fileInfo = dirInfo.GetFiles();
foreach (FileInfo info in fileInfo)
{
ListViewItem item = new ListViewItem();
item = listExplorer.Items.Add(info.Name);
item.SubItems.Add(info.LastAccessTime.ToString());
item.SubItems.Add(info.Length.ToString());
}
}
}
private void onMouseDown(object sender, MouseEventArgs e)
{
if (treeExplore.GetNodeAt(e.X, e.Y) != null)
{
compressMenuItem.Visible = true;
encryptMenuItem.Visible = true;
}
else
{
compressMenuItem.Visible=false;
encryptMenuItem.Visible=false;
}
}
本人是才学习,对于以上代码也是基本按照例子做的,,加载本地机子上的文件系统,我现在主要是想在listExplorer又点击文件,有弹出菜单,若是.zip的就解压缩,若是别的就实现压缩的功能,怎么编写代码,还有就是要用哪个命名空间,使用什么类呢?跪求解答!