Check access to file using UiPath

How to check if the read write permissions on a file using UiPath?

To check if write access is present on a file for the UiPath robot user, Write a code in an “Invoke Code” activity.
Arguments : 
  Name : path
  Direction :  In
  Type : String

  Name : result
  Direction : Out
  Type : Boolean
  Value : res

Dim writeAllow As Boolean = False
Dim writeDeny As Boolean = False
Dim dInfo As New DirectoryInfo(path)
Dim accessControlList As System.Security.AccessControl.DirectorySecurity = dInfo.GetAccessControl()
If(accessControlList Is Nothing) Then
 result = False
 Dim accessRules As System.Security.AccessControl.AuthorizationRuleCollection = accessControlList.GetAccessRules(True, True,GetType(System.Security.Principal.SecurityIdentifier))
 If accessControlList Is Nothing Then 
  result = False
  For Each rule As System.Security.AccessControl.FileSystemAccessRule In accessRules
   If (System.Security.AccessControl.FileSystemRights.Write And rule.FileSystemRights) <> System.Security.AccessControl.FileSystemRights.Write Then Continue For
   If rule.AccessControlType = System.Security.AccessControl.AccessControlType.Allow Then
    writeAllow = True
   ElseIf rule.AccessControlType = System.Security.AccessControl.AccessControlType.Deny Then
    writeDeny = True
   End If
  End If 
End If
result = writeAllow AndAlso Not writeDeny