private void resndbtn_Click(object sender, EventArgs e)
{
using (FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog())
{
DialogResult result = folderBrowserDialog.ShowDialog();
try
{
if (result == DialogResult.OK)
{
string folderName = folderBrowserDialog.SelectedPath;
if (!String.IsNullOrEmpty(folderName))
{
DirectoryInfo dir = new DirectoryInfo(folderName);
//如果非根路径且是系统文件夹则跳过
if (null != dir.Parent && dir.Attributes.ToString().IndexOf("System") > -1)
{
MessageBox.Show("获取目录下的文件名出错,请监控员查看是否存在异常文件!");
return;
}
//取得所有文件
FileInfo[] finfo = dir.GetFiles();
List<string> resndFilenameList = new List<string>();
for (int i = 0; i < finfo.Length; i++)
{
resndFilenameList.Add(finfo[i].Name);//不带路径的文件名
if (File.Exists("C:\QQ\" + finfo[i].Name))//判断是否已存在该文件,若存在则删除
File.Delete("C:\QQ\" + finfo[i].Name);//目的文件存在则删除
//未存在则将文件移到该目录下
File.Move(folderName + @"\" + finfo[i].Name, AppSettings.PathSendTLQ + finfo[i].Name);//目标文件已经存在;未找到源文件都会引发异常!
}
if (resndFilenameList.Count <= 0)
{
MessageBox.Show("您选择的目录为空!");
return;
}
}
else
{
MessageBox.Show("无效路径,请重新选择!");
}
}
}
catch
{
MessageBox.Show("未知异常,请重试!");
}
}//using
}