private void btnClear_Click(object sender, EventArgs e) { int count = 0; foreach (var item in ErrorfileIdList) { try { RB.AppendText("【" + DateTime.Now.ToString() + "】清除文件" + item + "\n"); if (cbxHS.Checked) { Directory.Delete(Path.GetDirectoryName(item), true); } else { Microsoft.VisualBasic.FileIO.FileSystem.DeleteDirectory(Path.GetDirectoryName(item), Microsoft.VisualBasic.FileIO.UIOption.AllDialogs, Microsoft.VisualBasic.FileIO.RecycleOption.SendToRecycleBin, Microsoft.VisualBasic.FileIO.UICancelOption.DoNothing); } count++; lblClear.Text = count.ToString(); } catch (Exception ex) { RB.AppendText("【" + DateTime.Now.ToString() + "】清除异常" + ex.Message + "\n"); } RB.AppendText("【" + DateTime.Now.ToString() + "】清除完毕" + "\n"); } }
private void StartExecAD() { btnClear.Enabled = false; lblError.Text = "0"; RB.Clear(); //获取数据库名称 string dbName = cmbDB.Text; string dbPath = txtPath.Text + "\\" + dbName; if (!Directory.Exists(dbPath)) { MessageBox.Show("没有需要处理得数据"); return; } DirectoryInfo TheFolder = new DirectoryInfo(dbPath); Thread.Sleep(100); System.Windows.Forms.Application.DoEvents(); RB.AppendText("【" + DateTime.Now.ToString() + "】扫描中..." + "\n"); foreach (var item in TheFolder.GetDirectories()) { Thread.Sleep(100); System.Windows.Forms.Application.DoEvents(); string fileid = item.Name; getFileID(item); } lblFileCount.Text = fileList.Count.ToString(); RB.AppendText("【" + DateTime.Now.ToString() + "】扫描完毕,开始整理垃圾数据...,这可能需要几分钟,请耐心等待..." + "\n"); foreach (var item in fileList) { Thread.Sleep(100); System.Windows.Forms.Application.DoEvents(); string path = Path.GetDirectoryName(item); string id = path.Substring(path.LastIndexOf(cmbDB.Text) + cmbDB.Text.Length).Replace("\\", ""); Item fileItem = inn.getItemById("File", id); if (fileItem.getItemCount() != 1) { ErrorfileIdList.Add(item); lblError.Text = ErrorfileIdList.Count.ToString(); RB.AppendText("【" + DateTime.Now.ToString() + "】无效文件" + item + "\n"); } fileIdList.Add(id); } RB.AppendText("【" + DateTime.Now.ToString() + "】整理完毕" + "\n"); btnClear.Enabled = true; }
public void ConsoleWriteLine(string text) { RB.AppendText(String.Format("{0}\n", text)); }