0

我目前正在用安全删除算法和东西重写一个文件删除工具。Wenn 我正在尝试递归浏览目录并删除其中的所有文件和所有子目录等。调试器将引发 stackoverflow 异常。

   private void wipeFile(string file)
   {
        bool ret = false;
        switch (m_algo)
        {
            case Algorithms.fastAlgo:
                ret = FastWipe.WipeFile(file);
                break;
            case Algorithms.safeAlgo:
                ret = CleanWipe.WipeFile(file, m_timesToWrite);
                break;
        }
        handleFileWiped(file, DateTime.Now, ret);
    }

    /// <summary>
    /// Wipes a directory recursively
    /// </summary>
    /// <param name="directory">Given subdir</param>
    private void deepWipe(string directory)
    {
        foreach (string file in Directory.GetFiles(directory))
        {
            wipeFile(file);
        }
        foreach (string subdir in Directory.GetDirectories(directory))
        {
            deepWipe(directory);
        }
        try
        {
            Directory.Delete(directory);
            handleDirectoryWiped(directory, DateTime.Now, true);
        }
        catch { handleDirectoryWiped(directory, DateTime.Now, false); }
    }
4

1 回答 1

3

改变这个:

 foreach (string subdir in Directory.GetDirectories(directory))
 {
     deepWipe(directory);
 }

至:

 foreach (string subdir in Directory.GetDirectories(directory))
 {
     deepWipe(subdir);
 }
于 2010-07-02T21:35:35.630 回答