1

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;
    }
4

2 回答 2

3

由于复制大文件夹不是单个操作,而是由许多单独的复制操作组成,因此 FileSystemWatcher 无法确定整个文件夹的复制操作何时完成。因此,它将分别为您提供有关每个文件的通知。我的建议是分别处理每个文件。复制的时候(触发FileSystemWatcher的事件),计算MD5,放入字典。

于 2009-07-13T12:32:18.020 回答
0

您应该知道的一件事是递归复制所有文件和文件夹是等待发生的堆栈溢出。有关如何将目录层次结构制作成非递归 IEnumerable 类的信息,请参阅此问题此博客文章。

于 2009-07-13T12:50:20.723 回答