Search code examples
shortcut-file

Get target data of a Windows shortcut via command


I have a folder with 16000 files, execpt some of them are shortcuts to files. Is there a command to extract the path and filename of the linked file, so I know where the physical file is?

Thanks.


Solution

  • For Unix:readlink is a command line tool that you can use, along with the find, to extract the path and filename of the linked file.

    find /path/to/your/folder -type l -exec readlink -f {} \;
    

    For windows: you can use the where and wmic commands in combination

    Get-ChildItem -Path "C:\path\to\your\folder" -Filter *.lnk -Recurse | ForEach-Object { $_.FullName; (New-Object -ComObject WScript.Shell).CreateShortcut($_.FullName).TargetPath }