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();
}
文章来源:
http://www.cnblogs.com/wangdetian168/archive/2008/10/17/1313258.html
posted on 2010-09-30 12:22
sanmao 阅读(73)
评论(0) 编辑 收藏