2013-11-19 11:34:25
int filesum = 0; //更新文件数
string LocalPath = Application.StartupPath + @"\";
//从配置文件App中取文件服务器更新目录:
string ServerPath = System.Configuration.ConfigurationManager.AppSettings["UpdateFilePath"];
if (Directory.Exists(ServerPath))
{
foreach (string SourceFile in Directory.GetFiles(ServerPath)) //循环取服务器更新路径文件
{
string FileName = Path.GetFileName(SourceFile);//取更新文件名
//if (FileName == "11.txt") continue;
//本地目录有相同文件名就需要判断是否为可用更新文件
if (File.Exists(LocalPath + FileName) == true)
{
DateTime dtLocal = File.GetLastWriteTime(LocalPath + FileName);//本地文件修改日期
DateTime dtUpdate = File.GetLastWriteTime(SourceFile);//更新目录文件的修改日期
if (dtUpdate != dtLocal)//可用更新
{
++filesum;
//this.lbl_FileMessage.Text = "正在复制文件:" + FileName + ",数量:" + filesum.ToString();
File.Copy(SourceFile, LocalPath + FileName, true);
}
}
else
{
++filesum;
//this.lbl_FileMessage.Text = "正在复制文件:" + FileName + ",数量:" + filesum.ToString();
File.Copy(SourceFile, LocalPath + FileName, true);
}
}
if (filesum > 0)
MessageBox.Show("刚才从服务器更新文件" + filesum.ToString() + "个,请重新运行!", "提示");
//this.lbl_text.Text = "OK! 文件检查更新完毕!";
//this.lbl_FileMessage.Text = "更新文件" + filesum.ToString() + "个。";
}