This commit is contained in:
Jonathan Jenne
2022-01-21 15:51:14 +01:00
parent 408dacf1b5
commit 0fa654bda0
6 changed files with 64 additions and 27 deletions

View File

@@ -75,6 +75,11 @@ Public Class File
Return oCleanName
End Function
''' <summary>
''' Reads the file at `FilePath` and computes a SHA256 Hash from its contents
''' </summary>
''' <param name="FilePath"></param>
''' <returns></returns>
Public Function GetChecksum(FilePath As String) As String
Try
Using oFileStream = IO.File.OpenRead(FilePath)
@@ -339,6 +344,24 @@ Public Class File
End Try
End Function
''' <summary>
''' Checks if a file is locked, ie. in use by another process.
''' </summary>
''' <remarks>
''' https://docs.microsoft.com/en-us/dotnet/standard/io/handling-io-errors
''' </remarks>
Public Function TestFileIsLocked(pFilePath As String) As Boolean
Try
Using stream As FileStream = IO.File.Open(FileMode.Open, FileAccess.Read, FileShare.None)
stream.Close()
End Using
Catch ex As Exception When ((ex.HResult And &HFFFF) = 32)
Return True
End Try
Return False
End Function
Public Function TestPathIsDirectory(Path As String) As Boolean
If Not Directory.Exists(Path) Then
Return False