Ejemplo n.º 1
0
 private static void DeleteDirectories(string[] directories)
 {
     foreach (string directory in directories)
     {
         string[] files = LongDirectory.GetFiles(directory, null, System.IO.SearchOption.TopDirectoryOnly);
         foreach (string file in files)
         {
             LongFile.Delete(file);
         }
         directories = LongDirectory.GetDirectories(directory, null, System.IO.SearchOption.TopDirectoryOnly);
         DeleteDirectories(directories);
         bool ok = NativeMethods.RemoveDirectory(GetWin32LongPath(directory));
         if (!ok)
         {
             ThrowWin32Exception();
         }
     }
 }
Ejemplo n.º 2
0
        private bool delete(string path)
        {
            bool result = false;

            if (LongDirectory.Exists(path))
            {
                string[] subs = LongDirectory.GetDirectories(path);
                foreach (string sub in subs)
                {
                    if (formClosing)
                    {
                        break;
                    }
                    delete(sub);
                }
                string[] files = LongDirectory.GetFiles(path);
                foreach (string file in files)
                {
                    if (formClosing)
                    {
                        break;
                    }
                    delete(file);
                }
                try
                {
                    LongDirectory.Delete(path);
                    result = true;
                }
                catch (Exception ex)
                {
                    if (ex.HResult == -2147024751 || ex.HResult == -2147467259)
                    {
                        txtLog.AppendText(string.Format("Directory is not empty: {0}\r\n", path));
                    }
                    else
                    {
                        txtLog.AppendText(string.Format("{0}\r\n", ex.Message));
                    }
                    result = false;
                }
                toolStripProgressBar1.Value++;
                Application.DoEvents();
            }
            else if (LongFile.Exists(path))
            {
                try
                {
                    LongFile.Delete(path);
                    result = true;
                }
                catch (Exception ex)
                {
                    txtLog.AppendText(string.Format("{0}: {1}\r\n", ex.Message, path));
                    result = false;
                }
                toolStripProgressBar1.Value++;
                Application.DoEvents();
            }
            return(result);
        }