complete new machine, should have said that.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace TEPFindFile
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnCompletedFiles_Click(object sender, EventArgs e)
{
folderBrowserDialog1.RootFolder = Environment.SpecialFolder.MyComputer;
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
txtCompletedFiles.Text = folderBrowserDialog1.SelectedPath.ToString();
folderBrowserDialog1.Reset();
}
}
private void btnSearchFolder_Click(object sender, EventArgs e)
{
folderBrowserDialog1.RootFolder = Environment.SpecialFolder.MyComputer;
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
txtSearchFolder.Text = folderBrowserDialog1.SelectedPath.ToString();
folderBrowserDialog1.Reset();
}
}
private void btnFindDups_Click(object sender, EventArgs e)
{
string pathCFiles = txtCompletedFiles.Text;
string[] arrCompletedDrawings = Directory.GetFiles(pathCFiles, "*.dwg");
string dupeFile = pathCFiles + "\\" + "Dupes.txt";
string pathLockedFiles = txtSearchFolder.Text;
progressBar1.Visible = true;
progressBar1.Minimum = 1;
progressBar1.Maximum = 1 + arrCompletedDrawings.Count();
progressBar1.Value = 1;
foreach (string dwg in arrCompletedDrawings)
{
string filedwg = dwg.Substring(dwg.LastIndexOf("\\") + 1);
LoadDirFiles(pathLockedFiles, true, filedwg, dupeFile, pathCFiles);
progressBar1.Value += 1;
Application.DoEvents();
}
progressBar1.Visible = false;
MessageBox.Show("Completed Searching for Duplicates");
}
private void LoadDirFiles(string Dir, bool CheckSubs, string dwgTF, string dupFile, string origPath)
{
string[] fls = Directory.GetFiles(Dir);
foreach (string fl in fls)
{
string path = fl.Substring(0, fl.LastIndexOf("\\"));
string filedwg = fl.Substring(fl.LastIndexOf("\\") + 1);
if (path.ToUpper() != origPath.ToUpper())
{
if (dwgTF.ToUpper() == filedwg.ToUpper())
{
WriteDups(fl, dupFile);
}
}
}
if (CheckSubs)
{
string[] dirs = Directory.GetDirectories(Dir);
foreach (string d in dirs)
{
LoadDirFiles(d, CheckSubs, dwgTF, dupFile, origPath);
}
}
}
private void txtCompletedFiles_Click(object sender, EventArgs e)
{
txtCompletedFiles.Select(0, txtCompletedFiles.TextLength);
}
private void txtSearchFolder_Click(object sender, EventArgs e)
{
txtSearchFolder.Select(0, txtSearchFolder.TextLength);
}
static void WriteDups(string dupDWG, string dupFile)
{
StreamWriter sw = new StreamWriter(dupFile, true);
sw.WriteLine(dupDWG);
sw.Close();
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
}
static class FileHelper
{
public static List<string> GetFilesRecursive(string b)
{
// 1.
// Store results in the file results list.
List<string> result = new List<string>();
// 2.
// Store a stack of our directories.
Stack<string> stack = new Stack<string>();
// 3.
// Add initial directory.
stack.Push(b);
// 4.
// Continue while there are directories to process
while (stack.Count > 0)
{
// A.
// Get top directory
string dir = stack.Pop();
try
{
// B
// Add all files at this directory to the result List.
result.AddRange(Directory.GetFiles(dir, "*.*"));
// C
// Add all directories at this directory.
foreach (string dn in Directory.GetDirectories(dir))
{
stack.Push(dn);
}
}
catch
{
// D
// Could not open the directory
}
}
return result;
}
}
}