views:

240

answers:

2

Hello, I'm facing an issue with filewatcher. My requirement is that when we copy a large folder of size one GB or more than that, FSW should log only one change that folder X has created, but not give the created events of files underneath X. And I wanted to calculate MD5 Checksums of the all those files which are copied with "X" folder. As copying of large files is taking a lot of time I'm not able to get all the files and sub folder names under X. I need to get all the filepaths to add to a dictionary data structure. Could you please advise on this.

    public static string[] GetFilesAndFolders(string path)
    {
        foreach (string dirs in Directory.GetDirectories(path))
        {
            fileandFolderNames[counter] = dirs;
            counter++;
            foreach (string files in Directory.GetFiles(dirs))
            {
                fileandFolderNames[counter] = files;
                counter++;
            }
            GetFilesAndFolders(dirs);
        }
        return fileandFolderNames;
    }
+2  A: 

Since copying a large folder is not a single operation, but instead consists of many separate copy operations, the FileSystemWatcher cannot determine when the copy operation of the whole folder is complete. Thus, it will give you a notification about each file separately. My suggestion is to handle each file separately. When it is copied (the event of FileSystemWatcher is triggered), calculate the MD5 and put it in the dictionary.

Vilx-
A: 

One thing you should know is that copying all the files and folders recursively is a stack overflow waiting to happen. See this question and this blog post for how to make a directory hierarchy into a non-recursive IEnumerable class.

plinth