diff --git a/Filesystem/File.vb b/Filesystem/File.vb index 45f25143..38ba28d6 100644 --- a/Filesystem/File.vb +++ b/Filesystem/File.vb @@ -39,13 +39,16 @@ Public Class File ''' Should the function continue with deleting when a file could not be deleted? ''' True if all files were deleted or if no files were deleted, otherwise false 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 + If Not Directory.Exists(Path) Then - _logger.Warn("Directory {0} does not exist") - Return False + Throw New DirectoryNotFoundException($"Path {Path} does not exist!") End If If FileKeepTime < 0 Or FileKeepTime > 1000 Then - Throw New ArgumentOutOfRangeException("FileKeepTime must be an integer between 0 and 1000") + Throw New ArgumentOutOfRangeException("FileKeepTime must be an integer between 0 and 1000!") End If Dim oUnableToDeleteCounter = 0 @@ -85,4 +88,10 @@ Public Class File Return True End Function + + Private Function TestPathIsDirectory(Path As String) As Boolean + Dim oIsDirectory As Boolean = (System.IO.File.GetAttributes(Path) And FileAttributes.Directory) = FileAttributes.Directory + Return oIsDirectory + End Function + End Class