powershell to resolve junction target path

后端 未结 7 1108
闹比i
闹比i 2020-12-09 15:32

In PowerShell, I need resolve the target path of a junction (symlink).

for example, say I have a junction c:\\someJunction whose target is c:\\te

相关标签:
7条回答
  • 2020-12-09 16:10

    At least in PSv5 it's as easy as this to list all targets of some dirs links (or further down a single one) and get it as objects and nicely formatted (e.g. all the *~ dirs are actually junctions):

    C:\Jaspersoft> ls | select name, target
    
    Name                          Target
    ----                          ------
    apache-websrv~                {C:\Program Files (x86)\Apache24\}
    jasperreports-server-cp-6.3.0 {}
    jasperreports-server-cp~      {C:\Jaspersoft\jasperreports-server-cp-6.3.0}
    jr-srv-cp~                    {C:\Jaspersoft\jasperreports-server-cp~}
    

    for one link:

    C:\Jaspersoft> ls . apache-websrv~ | select name, target
    
    Name           Target
    ----           ------
    apache-websrv~ {C:\Program Files (x86)\Apache24\}
    

    or (to just get the Target as a String value for the C:\Jaspersoft\apache-websrv~ junction):

    > ls  C:\Jaspersoft  apache-websrv~  | %{$_.target}
    C:\Program Files (x86)\Apache24\
    

    The standard ls would look like this for the examples:

    C:\Jaspersoft> ls
    
        Verzeichnis: C:\Jaspersoft
    
    
    Mode                LastWriteTime         Length Name
    ----                -------------         ------ ----
    d----l       01.04.2019     15:05                apache-websrv~
    d-----       02.04.2019     10:30                jasperreports-server-cp-6.3.0
    d----l       05.10.2018     15:19                jasperreports-server-cp~
    d----l       12.02.2019     11:46                jr-srv-cp~
    

    (Other answers contained this in a way as well but not easily visible/understandable)

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