How do you reveal a file?

Here is what I use:

Protected Sub doRevealFolderItem(f As FolderItem)
  'www.xojoitaliablog.com/evidenziare-un-file-sul-desktop
  If f = Nil Or Not f.Exists Then Return
  #If TargetDesktop Then
    If f.IsFolder Then
      'if f.Name.IndexOf(0, ".") >= 0 then f = f.parent 'dot in folder name therefore reveal the parent e.g. pages
      If f.isBundleMBS Then f = f.Parent
      f.Open(True)
      Return
      
    Else
      #If TargetMacOS Then
        '[Fix] Reveal in Finder now highlights the file itself, not just opens the folder, 
        'using shell.execute(""open --reveal /path/to/my\ file"") or Var ok as Boolean, ok = sendItemAE(""misc"", ""mvis"", ""com.apple.finder"", f) or NSWorkSpaceMBS.selectFile"
        'tempString = "open -R """ + f.NativePath + """"
        'tempShell.Execute(tempString)
        'if tempShell.ExitCode <> 0 then
        'f.parent.Open
        'end if
        'tempShell
        'Return
        
        Call NSWorkSpaceMBS.selectFile(f)
        Return
        
      #ElseIf TargetWindows Then
        Var tempShell As New Shell 'used by Linux
        Var tempString As String 'used by Linux
        
        'returnValue = WinOpenFolderAndSelectItemsMBS(f.parent, Array(f))
        'if returnValue <> 0 then
        'f.parent.Open
        'end if
        
        'tempString = "explorer.exe /select," + f.NativePath 'not revealing folder for MVV
        'tempString = "explorer.exe /select,""" + f.NativePath + """"
        tempString = "explorer.exe /root,/separate,/select,""" + f.NativePath + """" 'run on separate new process
        tempShell.Execute(tempString)
        'If tempShell.ExitCode <> 0 Then
        If tempShell.ExitCode > 1 Then 'Error 1 seems to be success, so don't open the window twice!
          f.Parent.Open(True)
        End If
        tempShell.Close
        
        Return
        
      #ElseIf TargetLinux Then
        Var tempShell As New Shell 'used by Linux
        Var tempString As String 'used by Linux
        
        tempString = "xdg-open """ + f.Parent.NativePath + """"
        tempShell.Execute(tempString)
        If tempShell.ExitCode <> 0 Then
          f.parent.Open
        End If
        Return
        
      #Else
        f = f.Parent
        f.Open
      #EndIf
    End If
  #EndIf
End Sub
2 Likes