C# 如何在对话框中显示移动的文件数和移动的文件名
我有一个移动功能,可以将文件从一个文件夹移动到另一个文件夹。。 我想知道如何在对话框中显示移动的文件总数和移动的文件名。或者任何想法 这里的问题是,一旦我按下移动所有文件移动,如果有一些重复的文件,它会在我的网格视图中显示错误消息。。rest文件开始不断移动。所以我需要一个方法,一旦所有文件都被移动。。我需要显示一个对话框,其中包含在对话框中移动的文件总数和文件名。。那有可能吗。。或者任何想法。。请把它寄出去 我真的很感激 我的代码:C# 如何在对话框中显示移动的文件数和移动的文件名,c#,visual-studio,listview,filelist,file-move,C#,Visual Studio,Listview,Filelist,File Move,我有一个移动功能,可以将文件从一个文件夹移动到另一个文件夹。。 我想知道如何在对话框中显示移动的文件总数和移动的文件名。或者任何想法 这里的问题是,一旦我按下移动所有文件移动,如果有一些重复的文件,它会在我的网格视图中显示错误消息。。rest文件开始不断移动。所以我需要一个方法,一旦所有文件都被移动。。我需要显示一个对话框,其中包含在对话框中移动的文件总数和文件名。。那有可能吗。。或者任何想法。。请把它寄出去 我真的很感激 我的代码: private void button3_Click(ob
private void button3_Click(object sender, EventArgs e)
{
update = false;
this.Enabled = false;
backgroundWorker2.RunWorkerAsync();
move();
backgroundWorker2.CancelAsync();
System.Threading.Thread.Sleep(500);
this.Enabled = true;
update = true;
}
public void move()
{
update = false;
string archieve_path = ini.ReadValue("Location", "Archive");
string release_path = ini.ReadValue("Location", "Release");
string draft_path = ini.ReadValue("Location", "Draft");
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
if ((!String.IsNullOrEmpty(dataGridView1.Rows[i].Cells["Draft Path"].Value.ToString()) && String.IsNullOrEmpty(dataGridView1.Rows[i].Cells["Release Path"].Value.ToString())) &&
(dataGridView1.Rows[i].Cells[0].Value != null && (bool)dataGridView1.Rows[i].Cells[0].Value))
{
string draftpath = dataGridView1.Rows[i].Cells["Draft Path"].Value.ToString();
string relasepath = dataGridView1.Rows[i].Cells["Release Path"].Value.ToString();
string archievepath = dataGridView1.Rows[i].Cells["Archive"].Value.ToString();
string draftname = System.IO.Path.GetFileName(draftpath);
if (relasepath != string.Empty && draftname.Equals(Path.GetFileName(relasepath), StringComparison.OrdinalIgnoreCase))
{
dataGridView1.Rows[i].Cells["Error"].Value = "Duplicate in Release: " + draftname + "";
dataGridView1.Rows[i].Cells["Error"].Style = new DataGridViewCellStyle { ForeColor = Color.Red };
continue;
}
if (archievepath != string.Empty && draftname.Equals(Path.GetFileName(archievepath), StringComparison.OrdinalIgnoreCase))
{
dataGridView1.Rows[i].Cells["Error"].Value = "Duplicate in Archive: " + draftname + "";
dataGridView1.Rows[i].Cells["Error"].Style = new DataGridViewCellStyle { ForeColor = Color.Red };
continue;
}
string newpath = System.IO.Path.Combine(release_path, draftname);
System.IO.File.Move(draftpath, newpath);
dataGridView1.Rows[i].Cells["Release Path"].Value = newpath;
dataGridView1.Rows[i].Cells["Draft Path"].Value = string.Empty;
dataGridView1.Rows[i].Cells[0].Value = false; //Checkbox
}
if ((!String.IsNullOrEmpty(dataGridView1.Rows[i].Cells["Draft Path"].Value.ToString())
&& !String.IsNullOrEmpty(dataGridView1.Rows[i].Cells["Release Path"].Value.ToString())) &&
(dataGridView1.Rows[i].Cells[0].Value != null && (bool)dataGridView1.Rows[i].Cells[0].Value))
{
string draftPath = dataGridView1.Rows[i].Cells["Draft Path"].Value.ToString();
string releasepath = dataGridView1.Rows[i].Cells["Release Path"].Value.ToString();
string archievepath = dataGridView1.Rows[i].Cells["Archive"].Value.ToString();
string draftname = System.IO.Path.GetFileName(draftPath);
string archievename = System.IO.Path.GetFileName(archievepath);
string releasename = System.IO.Path.GetFileName(releasepath);
if (archievepath != string.Empty && draftname.Equals(Path.GetFileName(archievepath), StringComparison.OrdinalIgnoreCase))
{
dataGridView1.Rows[i].Cells["Error"].Value = "Duplicate in Archive: " + draftname + "";
dataGridView1.Rows[i].Cells["Error"].Style = new DataGridViewCellStyle { ForeColor = Color.Red };
continue;
}
if (releasepath != string.Empty && draftname.Equals(Path.GetFileName(releasepath), StringComparison.OrdinalIgnoreCase))
{
dataGridView1.Rows[i].Cells["Error"].Value = "Duplicate in Release: " + draftname + "";
dataGridView1.Rows[i].Cells["Error"].Style = new DataGridViewCellStyle { ForeColor = Color.Red };
continue;
}
if (archievepath != string.Empty && releasename.Equals(Path.GetFileName(archievepath), StringComparison.OrdinalIgnoreCase))
{
dataGridView1.Rows[i].Cells["Error"].Value = "Duplicate in Archive: " + releasename + "";
dataGridView1.Rows[i].Cells["Error"].Style = new DataGridViewCellStyle { ForeColor = Color.Red };
continue;
}
string fName1 = System.IO.Path.GetFileNameWithoutExtension(draftPath);
string fName2 = System.IO.Path.GetFileNameWithoutExtension(releasepath);
string fName3 = System.IO.Path.GetFileNameWithoutExtension(archievepath);
var f1 = GetValue(fName1.ToCharArray()[fName1.Length - 2]) * 16 + GetValue(fName1.ToCharArray()[fName1.Length - 1]);
var f2 = GetValue(fName2.ToCharArray()[fName2.Length - 2]) * 16 + GetValue(fName2.ToCharArray()[fName2.Length - 1]);
// var f3 = GetValue(fName3.ToCharArray()[fName3.Length - 2]) * 16 + GetValue(fName3.ToCharArray()[fName3.Length - 1]);
if (f1 > f2)//till here
{
//moves from realse to archieve
string newpath = System.IO.Path.Combine(archieve_path, releasename); //draft name + archieve
System.IO.File.Move(releasepath, newpath);
dataGridView1.Rows[i].Cells["Release Path"].Value = string.Empty;
}
if (f1 < f2)
{
//moves draft to archieve
string newpath = System.IO.Path.Combine(archieve_path, draftname);
System.IO.File.Move(draftPath, newpath);
dataGridView1.Rows[i].Cells["Draft Path"].Value = string.Empty;
return;
}
string newpath1 = System.IO.Path.Combine(release_path, draftname);
System.IO.File.Move(draftPath, newpath1);
dataGridView1.Rows[i].Cells["Release Path"].Value = newpath1;
dataGridView1.Rows[i].Cells["Draft Path"].Value = string.Empty;
dataGridView1.Rows[i].Cells[0].Value = false; //Checkbox
}
}
update = true;
}
private void按钮3\u单击(对象发送者,事件参数e)
{
更新=假;
此.Enabled=false;
backgroundWorker2.RunWorkerAsync();
move();
backgroundWorker2.CancelAsync();
系统.线程.线程.睡眠(500);
this.Enabled=true;
更新=真;
}
公开作废动议()
{
更新=假;
字符串archieve_path=ini.ReadValue(“位置”、“存档”);
字符串release_path=ini.ReadValue(“位置”、“释放”);
字符串draft_path=ini.ReadValue(“位置”、“草稿”);
对于(int i=0;if2)//直到这里
{
//从realse移动到archieve
字符串newpath=System.IO.Path.Combine(archieve\u Path,releasename);//草稿名+archieve
系统
StringBuilder sbBody = new StringBuilder();
List<string> lstFiles = new List<string>();
foreach (string file in Directory.GetFiles(newpath, "*.txt"))
{
// msg.Attachments.Add(new System.Net.Mail.Attachment(file));
lstFiles.Add(file);
}