rendered paste bodyusing System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;
namespace DirectoryList
{
public partial class Form1 : Form
{
// Stream need to be public.
StreamWriter SW;
// Form declaration.
public Form1()
{
InitializeComponent();
}
// Select origin directory.
private void button1_Click(object sender, EventArgs e)
{
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
textBox1.Text = folderBrowserDialog1.SelectedPath;
}
}
// Select destiny file.
private void button2_Click(object sender, EventArgs e)
{
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
textBox2.Text = saveFileDialog1.FileName;
}
}
// Do the search.
private void button3_Click(object sender, EventArgs e)
{
// Stream file assign.
FileInfo f = new FileInfo(textBox2.Text);
SW = f.CreateText();
// Progressbar.
progressBar1.Minimum = 0;
// Search recursively.
DirSearch(textBox1.Text);
// Change label.
label3.Text = "Done";
// We are done.
SW.Close();
}
// Recursive search.
void DirSearch(string sDir)
{
// Lookup current directory.
foreach (string d in Directory.GetDirectories(sDir))
{
// Progressbar for this directory.
progressBar1.Maximum = Directory.GetFiles(d, "*.*").Length;
progressBar1.Value = 0;
// Lookup files.
foreach (string f in Directory.GetFiles(d,"*.*"))
{
// Get info and write.
FileInfo file = new FileInfo(f);
SW.WriteLine(file.Name);
// Change text.
label3.Text = "Progress - " + file.Name;
progressBar1.Value += 1;
this.Refresh();
}
// Recurse to next directory.
DirSearch(d);
}
}
}
}