Find out whether a file is a symbolic link in PowerShell

后端 未结 7 514
孤城傲影
孤城傲影 2020-12-14 00:19

I am having a PowerShell script which is walking a directory tree, and sometimes I have auxiliary files hardlinked there which should not be processed. Is there an easy way

7条回答
  •  孤街浪徒
    2020-12-14 01:03

    Try this:

    function Test-ReparsePoint([string]$path) {
      $file = Get-Item $path -Force -ea SilentlyContinue
      return [bool]($file.Attributes -band [IO.FileAttributes]::ReparsePoint)
    }
    

    It is a pretty minimal implementation, but it should do the trick. Note that this doesn't distinguish between a hard link and a symbolic link. Underneath, they both just take advantage of NTFS reparse points, IIRC.

提交回复
热议问题