Click here to Skip to main content
15,890,399 members
Home / Discussions / C#
   

C#

 
GeneralRe: bytes, bits, trues and falses.. Pin
Tomas Petricek12-May-03 8:58
Tomas Petricek12-May-03 8:58 
GeneralRe: bytes, bits, trues and falses.. Pin
dazinith12-May-03 9:22
dazinith12-May-03 9:22 
GeneralRe: bytes, bits, trues and falses.. Pin
Tomas Petricek12-May-03 9:31
Tomas Petricek12-May-03 9:31 
GeneralRe: bytes, bits, trues and falses.. Pin
Jim Stewart12-May-03 6:47
Jim Stewart12-May-03 6:47 
GeneralRe: bytes, bits, trues and falses.. Pin
leppie12-May-03 6:58
leppie12-May-03 6:58 
GeneralRe: bytes, bits, trues and falses.. Pin
Wesner Moise19-May-03 19:01
Wesner Moise19-May-03 19:01 
Generalcatch exception from webservice in smartclients Pin
troels_sorensen12-May-03 5:08
troels_sorensen12-May-03 5:08 
GeneralNot enough files in the list Pin
Darf Fader12-May-03 4:57
Darf Fader12-May-03 4:57 
Hi,

this has got a bug that I cannot fathom, it is happily traversing through all the folders that it finds and checks all the files that it comes across with what is stored in the list. Unfortunately, the only files stored in the list, come from the working directory rather than the whole path.

As I step through it, I can see it checking all the files, but I cannot see why it stops collecting filenames after completing a scan of the first folder !
public class MainForm : System.Windows.Forms.Form
{
    // left out

    public void DirSearch(string path)
    {
        try
        {
            foreach(string file in Directory.GetFiles(path))
            {
                Original original = new Original(new FileInfo(file));
                original.CheckDirectory(new DirectoryInfo(path));

                if(original.HasDuplicates())
                {
                    listViewResult.Items.Add(file);

                    foreach(string duplicate in original.GetDuplicates())
                    {
                        listViewResult.Items.Add(duplicate);
                    }
                }
            }
        }
        catch(Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }
}

public class Duplicate
{
    private FileInfo _info;

    public Duplicate(FileInfo info)
    {
        this._info = info;
    }

    public bool IsDuplicate(FileInfo info)
    {
        return (_info.Name == info.Name) &&
            (_info.Length == info.Length) &&
            (_info.LastWriteTime == info.LastWriteTime) &&
            (_info.DirectoryName != info.DirectoryName);
    }
}

public class Original : Duplicate
{
    private ArrayList _list = new ArrayList();

    public Original(FileInfo info) : base(info) {}

    public void CheckFile(FileInfo info)
    {
        if(base.IsDuplicate(info))
        {
            this._list.Add(info.FullName);
        }
    }

    public void CheckDirectory(DirectoryInfo dirInfo)
    {
        foreach(FileInfo fileInfo in dirInfo.GetFiles())
        {
            CheckFile(fileInfo);
        }

        foreach(DirectoryInfo subDirInfo in dirInfo.GetDirectories())
        {
            CheckDirectory(subDirInfo);
        }
    }

    public IList GetDuplicates()
    {
        return this._list;
    }

    public bool HasDuplicates()
    {
        return (this._list.Count > 0);
    }
}


tia,
GeneralRe: Not enough files in the list Pin
Darf Fader12-May-03 23:10
Darf Fader12-May-03 23:10 
QuestionAre XML comments working properly in 2003? Pin
12-May-03 3:12
suss12-May-03 3:12 
QuestionUpdating a datagrid control? Pin
Manster12-May-03 2:31
Manster12-May-03 2:31 
Generalintegrate with outlook Pin
Roger Alsing12-May-03 2:07
Roger Alsing12-May-03 2:07 
GeneralAlways on top Pin
ardentOne12-May-03 1:39
ardentOne12-May-03 1:39 
GeneralRe: Always on top Pin
Tomas Petricek12-May-03 2:19
Tomas Petricek12-May-03 2:19 
GeneralRe: Always on top Pin
leppie12-May-03 6:55
leppie12-May-03 6:55 
GeneralDiferent between SmoothingMode.AntiAlias and SmoothingMode.HighQuality Pin
Wizard_0111-May-03 23:38
Wizard_0111-May-03 23:38 
GeneralRe: Diferent between SmoothingMode.AntiAlias and SmoothingMode.HighQuality Pin
J. Dunlap12-May-03 8:23
J. Dunlap12-May-03 8:23 
GeneralRe: Diferent between SmoothingMode.AntiAlias and SmoothingMode.HighQuality Pin
Wesner Moise19-May-03 19:03
Wesner Moise19-May-03 19:03 
GeneralWeb monitoring (Packet Sniffing) code Pin
aviyam11-May-03 22:35
aviyam11-May-03 22:35 
GeneralRegular Expresion Pin
mkomasi11-May-03 20:10
mkomasi11-May-03 20:10 
GeneralRe: Regular Expresion Pin
mkomasi12-May-03 20:08
mkomasi12-May-03 20:08 
GeneralWeb Services (Weather & Sports) Pin
Mike_V11-May-03 16:16
Mike_V11-May-03 16:16 
GeneralRe: Web Services (Weather & Sports) Pin
Kant11-May-03 16:50
Kant11-May-03 16:50 
GeneralRe: Web Services (Weather & Sports) Pin
Mike_V11-May-03 17:16
Mike_V11-May-03 17:16 
GeneralRe: Web Services (Weather & Sports) Pin
J. Dunlap11-May-03 17:33
J. Dunlap11-May-03 17:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.