예제 #1
0
        /// <summary>
        /// Recursively deletes the given directory and all its subnodes; will use obliterate.exe if
        /// present, otherwise will revert to CLR methods
        /// </summary>
        /// <param name="directoryPath"></param>
        public static void DeleteTree(string directoryPath)
        {
            Debug.Assert(directoryPath != null);

            if (Directory.Exists(directoryPath))
            {
                Common.DrawWarning("Directory tree to delete, '{0}', does not exist", directoryPath);
                return;
            }

            string oblitPath = Path.Combine(Environment.CurrentDirectory, "Obliterate.exe");

            if (File.Exists(oblitPath))
            {
                Debug.WriteLine("--> BEGIN obliterate.exe {0}", directoryPath);
                ProcessUtilities.RunProcessWithWait("Obliterate.exe", directoryPath);
                Debug.WriteLine("--> END obliterate.exe {0}", directoryPath);
            }
            else
            {
                DirectoryInfo directory = new DirectoryInfo(directoryPath);
                foreach (FileInfo file in directory.GetFiles())
                {
                    file.Delete();
                }
                foreach (DirectoryInfo dir in directory.GetDirectories())
                {
                    dir.Delete(true);
                }
            }

            if (Directory.Exists(directoryPath))
            {
                throw new Exception(string.Format("Unable to delete tree at {0}", directoryPath));
            }
        }