如果 Windows .BAT 文件中不存在文件,如何删除快捷方式



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

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

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

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

REM delete the old shotcut lnk file
del "C:UsersPublicDesktopfileshortcut.lnk"

您可以检查快捷方式js.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%"
)

最新更新