jj: test if path is directory
This commit is contained in:
parent
f939e0760c
commit
73a5f34587
@ -39,13 +39,16 @@ Public Class File
|
|||||||
''' <param name="ContinueOnError">Should the function continue with deleting when a file could not be deleted?</param>
|
''' <param name="ContinueOnError">Should the function continue with deleting when a file could not be deleted?</param>
|
||||||
''' <returns>True if all files were deleted or if no files were deleted, otherwise false</returns>
|
''' <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
|
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
|
If Not Directory.Exists(Path) Then
|
||||||
_logger.Warn("Directory {0} does not exist")
|
Throw New DirectoryNotFoundException($"Path {Path} does not exist!")
|
||||||
Return False
|
|
||||||
End If
|
End If
|
||||||
|
|
||||||
If FileKeepTime < 0 Or FileKeepTime > 1000 Then
|
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
|
End If
|
||||||
|
|
||||||
Dim oUnableToDeleteCounter = 0
|
Dim oUnableToDeleteCounter = 0
|
||||||
@ -85,4 +88,10 @@ Public Class File
|
|||||||
|
|
||||||
Return True
|
Return True
|
||||||
End Function
|
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
|
End Class
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user