Exemple #1
0
        private void Undo_changes_Click(object sender, EventArgs e)
        {
            int count = 1;

            for (int i = 0; i < filenameList.Count; i++)
            {
                names fn = filenameList[i];

                filenameList[i].status = "未执行";
                FileInfo fi = new FileInfo(fn.newname);

                if (fi.Exists)
                {
                    fi.MoveTo(fn.oldname);
                    filenameList[i].status = "成功";
                    count++;
                }
                else
                {
                    if (MessageBox.Show(fn.newname + "不存在,导致更名" + fn.oldname + " 失败,是否继续?", "", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
                    {
                        filenameList[i].status = "失败";
                        break;
                    }
                }
            }
            save_log(1);
            MessageBox.Show("还原" + count + "文件");
        }
Exemple #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            int count = 1;

            for (int i = 0; i < listBox1.Items.Count; i++)
            {
                names item = new names();

                item.oldname = listBox1.Items[i].ToString();

                FileInfo fi = new FileInfo(item.oldname);


                string ext = fi.Extension;

                if (fileEXchange.Checked && fileEX.Text.Trim() != "" && fileEX.Text[0] == '.')
                {
                    ext = fileEX.Text;
                }

                if (ischangeNum.Checked)
                {
                    item.newname = fi.Directory.FullName + "\\" + (i + 1) + "" + ext;
                }

                if (!filenameList.Exists(ex => ex.oldname == item.oldname))
                {
                    filenameList.Add(item);
                }

                if (fi.Exists)
                {
                    fi.MoveTo(item.newname);
                    filenameList[i].status = "成功";
                    count++;
                }
                else
                {
                    if (MessageBox.Show(item.oldname + "不存在,导致更名" + item.newname + " 失败,是否继续?", "", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
                    {
                        filenameList[i].status = "失败";

                        break;
                    }
                }
            }
            save_log(0);
            MessageBox.Show("更名" + count + "文件");
        }