【问题标题】:How to delete a shortcut if a file does not exists in a Windows .BAT file?如果 Windows .BAT 文件中不存在文件,如何删除快捷方式?
【发布时间】:2016-06-02 03:29:13
【问题描述】:

我的文件C:\testing\file.exe 已删除,但快捷方式仍保留在桌面上。

如何使用 .bat 文件删除快捷方式?

如果我手动删除它可以工作,但我必须编写一个带有一些更新的 .bat 文件,其他用户将在他们的笔记本电脑上运行相同的脚本。

这是我的 .bat 文件中的命令

REM delete the old shotcut lnk file
del "C:\Users\Public\Desktop\fileshortcut.lnk"

【问题讨论】:

    标签: windows batch-file


    【解决方案1】:

    您可以检查shortcutjs.bat。使用-examine 开关可以列出快捷方式属性。如果您在同一目录中有快捷方式,请使用:

    @echo off
    
    :: Set the path to the shortcut you want to check
    set "shortcut=C:\Shortcut.lnk"
    
    for /f "tokens=1* delims=:" %%A in ('shortcutjs.bat -examine "%shortcut%"^|findstr /b /i "Target"') do (
        set "target=%%B"
    )
    echo %target%
    if not exist "%target%" (
        REM if the command is ok delete the ECHO word bellow
        echo del /q /f "%shortcut%"
    )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多