Find out whether a file is a symbolic link in PowerShell

后端 未结 7 477
孤城傲影
孤城傲影 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:09

    My results on Vista, using Keith Hill's powershell script to test symlinks and hardlinks:

    c:\markus\other>mklink symlink.doc \temp\2006rsltns.doc
    symbolic link created for symlink.doc <<===>> \temp\2006rsltns.doc
    
    c:\markus\other>fsutil hardlink create HARDLINK.doc  \temp\2006rsltns.doc
    Hardlink created for c:\markus\other\HARDLINK.doc <<===>> c:\temp\2006rsltns.doc
    
    c:\markus\other>dir
     Volume in drive C has no label.
     Volume Serial Number is C8BC-2EBD
    
     Directory of c:\markus\other
    
    02/12/2010  05:21 PM    <DIR>          .
    02/12/2010  05:21 PM    <DIR>          ..
    01/10/2006  06:12 PM            25,088 HARDLINK.doc
    02/12/2010  05:21 PM    <SYMLINK>      symlink.doc [\temp\2006rsltns.doc]
                   2 File(s)         25,088 bytes
                   2 Dir(s)   6,805,803,008 bytes free
    
    c:\markus\other>powershell \script\IsSymLink.ps1 HARDLINK.doc
    False
    
    c:\\markus\other>powershell \script\IsSymLink.ps1 symlink.doc
    True
    

    It shows that symlinks are reparse points, and have the ReparsePoint FileAttribute bit set, while hardlinks do not.

    0 讨论(0)
提交回复
热议问题