以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- [求助]计划任务删除文件 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=73951) |
-- 作者:blsu33 -- 发布时间:2015/8/29 23:14:00 -- [求助]计划任务删除文件 老师, 计划任务执行有错误,请您指导一下 Dim y,m,d As Integer Dim dFile As New Dictionary(Of Date, String) Dim drs,drs2 As List (of DataRow) drs2=DataTables("备份").Select("[备份类型]=\'账套备份\'") For Each dr2 As DataRow In drs2 Dim namelen As Integer=dr2("备份计划名称").Length Dim filelen As Integer=dr2("备份路径").Length For Each File As String In FileSys.GetFiles(dr2("备份路径")) If File.SubString(filelen,namelen)=dr2("备份计划名称") Then dFile.Add(new Date(File.SubString(File.Length-12,8)),File) End If Next For Each k As Date In dFile.Keys DateYMD(Date.Now,dFile(k),y,m,d) If d>=dr2("删除旧备份天数") Then \'如果距离上次备份已经超过天数的部分 If FileSys.FileExists("& dFile(k).Values &") Then FileSys.DeleteFile("& dFile(k).Values &",2,2) End If End If Next dFile.Clear Next |
-- 作者:大红袍 -- 发布时间:2015/8/30 10:06:00 -- Dim y,m,d As Integer Dim dFile As New List(Of String) Dim drs,drs2 As List (of DataRow) drs2=DataTables("备份").Select("[备份类型]=\'账套备份\'") For Each dr2 As DataRow In drs2 Dim namelen As Integer=dr2("备份计划名称").Length Dim filelen As Integer=dr2("备份路径").Length For Each File As String In FileSys.GetFiles(dr2("备份路径")) If File.SubString(filelen,namelen)=dr2("备份计划名称") Then Dim ifo As new FileInfo(file) Dim sp As TimeSpan = Date.Now - ifo.CreationTime If sp.TotalDays>=dr2("删除旧备份天数") Then \'如果距离上次备份已经超过天数的部分 dFile.Add(File) End If End If Next Next For Each f As string In dFile FileSys.DeleteFile(f,2,2) Next |