jj: throw exception instead of swallowing

This commit is contained in:
Jonathan Jenne
2018-11-09 15:54:51 +01:00
parent 5748d37227
commit 734becb971
10 changed files with 15 additions and 389 deletions

View File

@@ -30,20 +30,16 @@ Public Class File
End Sub
''' <summary>
''' Removes files in a directory filtered by filename, extension and last write date.
''' Removes files in a directory filtered by filename, extension and last write date
''' </summary>
''' <param name="Path">The directory in which files will be deleted</param>
''' <param name="FileKeepTime">Only delete files which are older than x days. Must be between 0 and 1000 days.</param>
''' <param name="FileBaseName">A filename filter which will be checked</param>
''' <param name="FileExtension">A file extension which will be checked</param>
''' <param name="ContinueOnError">Should the function continue with deleting when a file could not be deleted?</param>
''' <exception cref="ArgumentException">When Path is not a directory</exception>
''' <exception cref="DirectoryNotFoundException">When Path was not found</exception>
''' <exception cref="ArgumentOutOfRangeException">When FileKeepTime is below 0 or above 1000</exception>
''' <returns>True if all files were deleted or if no files were deleted, otherwise false</returns>
Public Function RemoveFiles(Path As String, FileKeepTime As Integer, FileBaseName As String, Optional FileExtension As String = "log", Optional ContinueOnError As Boolean = True) As Boolean
If Not TestPathIsDirectory(Path) Then
Throw New ArgumentException($"Path {Path} is not a directory!")
End If
@@ -97,4 +93,5 @@ Public Class File
Dim oIsDirectory As Boolean = (System.IO.File.GetAttributes(Path) And FileAttributes.Directory) = FileAttributes.Directory
Return oIsDirectory
End Function
End Class