Als je ook niet wil dat er een melding wordt weergegeven, zul je eerst moeten controleren of het bestand in gebruik is (bron):
Visual Basic code: Public Sub DeleteFiles(ByVal Folder As System.IO.DirectoryInfo)
For Each sFile As System.IO.FileInfo In Folder.GetFiles() Try If Not FileInUse(sFile) Then sFile.Delete() Catch End Try Next
End Sub
Public Function FileInUse(ByVal myFile As System.IO.FileInfo) As Boolean
If myFile.Exists Then Try Dim F As Integer = FreeFile() FileOpen(F, myFile.FullName, OpenMode.Binary, OpenAccess.ReadWrite, OpenShare.LockReadWrite) FileClose(F) Catch Return True End Try End If
End Function
Groetjes |