【发布时间】:2012-10-02 07:58:35
【问题描述】:
我正在尝试以编程方式清除我的 temps 文件夹,但它无法删除正在使用的文件,只要删除所有未使用的文件就可以了。但是,我的代码基本上要求我们删除全部或不删除,而不仅仅是那些未使用的。
下面是代码,谁能告诉我如何解决这个问题?
'Deletes files in temporary directory...
Dim MYDAYS_2 As String
Dim MYTEMPFOLDER As String = System.IO.Path.GetTempPath
'this reads the regestry key otherwise gives a default value in its place (365)...
MYDAYS_2 = Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\AA", "HELLO", "365")
'Deletes all files older then the day specifyed in the variable MDAYS...
For Each file As IO.FileInfo In New IO.DirectoryInfo(MYTEMPFOLDER).GetFiles("*.*")
If (Now - file.CreationTime).Days > MYDAYS_2 Then file.Delete()
Next
【问题讨论】:
标签: vb.net file delete-file temp