日期:2014-05-18 浏览次数:20714 次
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.Threading;
namespace 为硬盘文件建立索引
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
/// <summary>
/// 文件路径
/// </summary>
string fpath = "";
/// <summary>
/// 初始化路径
/// </summary>
/// <param name="rootDirectory"></param>
private void BeginWrite(string rootDirectory)
{
fpath = @rootDirectory + "index.txt";
}
/// <summary>
/// 写一行数据
/// </summary>
/// <param name="Text"></param>
private void WriteText(string Text)
{
File.AppendAllText(fpath, Text + "\r\n");
}
/// <summary>
/// 创建索引按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnCreateIndex_Click(object sender, EventArgs e)
{
DriveInfo[] DriveInfos = DriveInfo.GetDrives();
foreach (DriveInfo di in DriveInfos)
{
if (di.DriveType == DriveType.Fixed)
{
string rootDirectory = di.RootDirectory.FullName;
///textBoxRoot.Text输入的盘符(如:H)
if (rootDirectory.StartsWith(textBoxRoot.Text.Trim().ToUpper()))