zj123.SQLDB.DbAccess dba = new zj123.SQLDB.DbAccess(this.textBox2.Text.Trim());
//插入临时表数据--对应年月的
string tempInsertSql = "insert into tempDataFiles([FileName]) select [FileName] from datafiles where [filename] like '%"+this.textBox1.Text.Trim()+"%'";
string tempDeleteSql = "delete from tempDataFiles";
dba.GetState(tempDeleteSql + ";" + tempInsertSql + ";");
StringBuilder sbsql = new StringBuilder("delete from DriveFiles;");
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(this.folderBrowserDialog1.SelectedPath);
foreach (System.IO.FileInfo fi in dir.GetFiles())
{
sbsql.AppendFormat("insert into DriveFiles([FileName],[FilePath]) values('{0}','{1}');",fi.Name,fi.FullName);
}
foreach(System.IO.DirectoryInfo di in dir.GetDirectories())
{
foreach (System.IO.FileInfo fi in di.GetFiles())
{
sbsql.AppendFormat("insert into DriveFiles([FileName],[FilePath]) values('{0}','{1}');", fi.Name, fi.FullName);
}
}
dba.GetState(sbsql.ToString());
string tempDeletSql = "select * from DriveFiles where [FileName] not in(select [FileName] from tempDataFiles)";
DataTable dt = dba.GetTable(tempDeletSql);
int i = 0;
int a = dt.Rows.Count;
foreach (DataRow dr in dt.Rows)
{
System.IO.File.Delete(Convert.ToString(dr["FilePath"]).Trim());
i++;
this.label4.Text = "正在删除" + i.ToString()+"---共"+a.ToString().ToString();
Application.DoEvents();
}