以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  删除指定天数文件  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=177606)

--  作者:狐表(小白)
--  发布时间:2022/5/27 23:36:00
--  删除指定天数文件
代码如下,删除指定文件夹大于等于2天的文件,功能已经实现,老师给看看有没有其它方式再精简一下代码,感觉有些冗余,又不知道怎么精简。谢谢!
文件命名格式:例如:5.27_张三.html

Dim dir As new io.DirectoryInfo(ProjectPath & "web\\fl\\gongzi\\")
For Each File As object In dir.GetFiles
    Dim s as string  = file.name 
    Dim idx As Integer = s.LastIndexOf("_")
    Dim ext As String  = s.SubString(0,idx)
    Dim dte as date = CDate(ext)
    Dim t As TimeSpan
    t = Date.Today - dte
    If t.TotalDays >= 2 then
       file.delete
    End If 
Next
[此贴子已经被作者于2022/5/27 23:37:01编辑过]

--  作者:有点蓝
--  发布时间:2022/5/28 9:14:00
--  
只能这样