You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过命令获取Windows快捷方式的目标文件路径与文件名?

提取快捷方式的目标路径与文件名的命令方法

针对不同操作系统,以下是无需第三方工具的原生命令方案:

Windows 系统(处理 .lnk 快捷方式)

实时查看结果

使用 PowerShell 遍历目标文件夹下所有 .lnk 文件,直接输出快捷方式名称和对应的物理文件路径:

Get-ChildItem -Path "你的文件夹绝对路径" -Filter *.lnk -Recurse | ForEach-Object {
    $shell = New-Object -ComObject WScript.Shell
    $target = $shell.CreateShortcut($_.FullName).TargetPath
    Write-Host "快捷方式: $($_.Name) | 物理文件路径: $target"
}

导出为 CSV 文件(便于批量查看)

如果需要将结果保存为结构化文件,可导出到 CSV:

Get-ChildItem -Path "你的文件夹绝对路径" -Filter *.lnk -Recurse | ForEach-Object {
    $shell = New-Object -ComObject WScript.Shell
    $shortcut = $shell.CreateShortcut($_.FullName)
    [PSCustomObject]@{
        快捷方式名称 = $_.Name
        物理文件路径 = $shortcut.TargetPath
        物理文件名 = [System.IO.Path]::GetFileName($shortcut.TargetPath)
    }
} | Export-Csv -Path "快捷方式目标列表.csv" -Encoding UTF8 -NoTypeInformation

Linux 系统(处理 .desktop 快捷方式)

Linux 桌面环境的快捷方式多为 .desktop 文件,可通过提取文件内的 Exec 字段获取目标路径:

find /你的文件夹绝对路径 -name "*.desktop" -type f | while read desktop_file; do
    shortcut_name=$(basename "$desktop_file")
    # 提取Exec字段并移除后续启动参数
    target_path=$(grep -E '^Exec=' "$desktop_file" | sed 's/^Exec=//' | sed 's/ %.*//')
    echo "快捷方式: $shortcut_name | 物理文件路径: $target_path"
done

macOS 系统(处理 Alias 别名)

AppleScript 方案(可视化或脚本运行)

tell application "Finder"
    set targetFolder to POSIX file "/你的文件夹绝对路径" as alias
    set aliasItems to every item of targetFolder whose kind is "Alias"
    repeat with itemRef in aliasItems
        set aliasName to name of itemRef
        set targetPath to POSIX path of original item of itemRef
        set targetName to name of original item of itemRef
        log "快捷方式: " & aliasName & " | 物理文件路径: " & targetPath & " | 物理文件名: " & targetName
    end repeat
end tell

命令行方案(结合 mdls)

find /你的文件夹绝对路径 -type f -exec mdls -name kMDItemKind -name kMDItemDisplayName -name kMDItemOriginalItem {} \; | awk '
    /kMDItemKind = "Alias"/ { in_alias=1 }
    in_alias && /kMDItemDisplayName =/ { name=$3; gsub(/"/, "", name) }
    in_alias && /kMDItemOriginalItem =/ { path=$3; gsub(/"/, "", path); print "快捷方式: " name " | 物理文件路径: " path; in_alias=0 }
'

内容的提问来源于stack exchange,提问作者tt_time

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 20:05:13