Пример #1
0
 private void scan(string path)
 {
     if (LongDirectory.Exists(path))
     {
         scannedFiles++;
         foreach (string sub in LongDirectory.GetDirectories(path))
         {
             if (formClosing)
             {
                 break;
             }
             scan(sub);
         }
         foreach (string file in LongDirectory.GetFiles(path))
         {
             if (formClosing)
             {
                 break;
             }
             scan(file);
         }
     }
     else if (LongFile.Exists(path))
     {
         scannedFiles++;
     }
     Application.DoEvents();
 }
Пример #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);
        }