Public Class Form1
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
ClearFloder(Environment.GetFolderPath(Environment.SpecialFolder.Cookies))
ClearFloder(Environment.GetFolderPath(Environment.SpecialFolder.History))
Dim Temp As String = Environment.GetFolderPath(Environment.SpecialFolder.History)
Temp = Temp.Replace("History", "Temp")
ClearFloder(Temp)
ClearFloder(Environment.GetFolderPath(Environment.SpecialFolder.InternetCache))
ClearFloder(Environment.GetFolderPath(Environment.SpecialFolder.Templates))
End
End Sub
Public Shared Sub ClearFloder(ByVal FloderPath As String)
On Error Resume Next '跳过删除不了的文件或文件夹
'删除所有文件夹
Dim I As Long
Dim SubFloders As String() = Directory.GetDirectories(FloderPath)
For I = 0 To SubFloders.Length - 1
IO.Directory.Delete(SubFloders(I))
My.Computer.FileSystem.DeleteDirectory(SubFloders(I), FileIO.DeleteDirectoryOption.DeleteAllContents)
Next
'删除所有文件
Dim Files As String() = Directory.GetFiles(FloderPath)
For I = 0 To Files.Length - 1
'Form1.ListBox1.Items.Add(Files(I))
IO.File.Delete(Files(I))
'My.Computer.FileSystem.DeleteFile(Files(I), FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.DeletePermanently)
Next
End Sub
'没有变量返回Temp这个目录
'Environment.SpecialFolder.DesktopDirectory和Desktop是不一样的
End Class
|
暂时没有评论
发表评论 - 不要忘了输入验证码哦! |