代码如下,删除指定文件夹大于等于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编辑过]