private void button2_Click(object sender, EventArgs e)
{
 
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("FilePath.xml");
XmlNodeList xn = xmlDoc.SelectSingleNode("Test").ChildNodes;
string strPath = string.Empty;
foreach (XmlNode item in xn)
{
if (item.Name.Equals("Path"))
strPath = item.InnerText.Trim();
}
FolderBrowserDialog dialog = new FolderBrowserDialog();
dialog.SelectedPath = strPath;
dialog.Description = "请选择文件夹路径";
dialog.ShowNewFolderButton = false;
if (dialog.ShowDialog() == DialogResult.OK)
{
txtFile.Text = dialog.SelectedPath;
}
}
 
private void button3_Click(object sender, EventArgs e)
{
FolderBrowserDialog dialog = new FolderBrowserDialog();
dialog.Description = "请选择存放路径";
dialog.ShowNewFolderButton = false;
if (dialog.ShowDialog() == DialogResult.OK)
{
txtEndFile.Text = dialog.SelectedPath;
}
}
 
private void button1_Click(object sender, EventArgs e)
{
try
{
if (string.IsNullOrEmpty(txtFile.Text))
{
MessageBox.Show("请选择路径!");
return;
}
if (string.IsNullOrEmpty(txtEndFile.Text))
{
MessageBox.Show("请选择存放路径!");
return;
}
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("FilePath.xml");
//XmlNode root = xmlDoc.SelectSingleNode("Test");//查找<Test>
XmlNodeList nodeList = xmlDoc.SelectSingleNode("Test").ChildNodes;//获取bookstore节点的所有子节点
foreach (XmlNode xn in nodeList)//遍历所有子节点
{
XmlElement xe = (XmlElement)xn;//将子节点类型转换为XmlElement类型
if (xe.Name.Equals("Path"))//如果name值为“Path”
{
xe.InnerText = txtFile.Text;//则修改
break;
}
}
xmlDoc.Save("FilePath.xml");//保存。
button1.Enabled = false;
 
//C#遍历指定文件夹中的所有文件
DirectoryInfo TheFolder = new DirectoryInfo(txtFile.Text);
//遍历文件夹
//foreach(DirectoryInfo NextFolder in TheFolder.GetDirectories())
//this.listBox1.Items.Add(NextFolder.Name);
//遍历文件
foreach (FileInfo NextFile in TheFolder.GetFiles())
{
if (NextFile.Name.Length >= Convert.ToInt32(textBox1.Text))
File.Copy(txtFile.Text + "\\" + NextFile.Name, txtEndFile.Text + "\\" + NextFile.Name.Remove(Convert.ToInt32(textBox2.Text), Convert.ToInt32(textBox3.Text)));
else
File.Copy(txtFile.Text + "\\" + NextFile.Name, txtEndFile.Text + "\\" + NextFile.Name);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
button1.Enabled = true;
MessageBox.Show("处理完成");
}
private void SetText()
{
try
{
if (!string.IsNullOrEmpty(textBox3.Text) && !string.IsNullOrEmpty(textBox2.Text) &&
!string.IsNullOrEmpty(textBox1.Text))
{
if (textBox5.Text.Length >= Convert.ToInt32(textBox1.Text))
textBox4.Text = textBox5.Text.Remove(Convert.ToInt32(textBox2.Text),
Convert.ToInt32(textBox3.Text));
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
 
private void textBox3_TextChanged(object sender, EventArgs e)
{
SetText();
}
 
private void textBox2_TextChanged(object sender, EventArgs e)
{
SetText();
}
 
private void textBox1_TextChanged(object sender, EventArgs e)
{
SetText();
}
 
private void CopyPicForm_Load(object sender, EventArgs e)
{
SetText();
}
posted on 2016-09-22 14:48  zishen  阅读(1312)  评论(0编辑  收藏  举报