Board logo

标题: [其他] 批处理如何删除桌面非快捷方式? [打印本页]

作者: 1078292299    时间: 2021-2-17 20:34     标题: 批处理如何删除桌面非快捷方式?

批处理如何删除桌面非快捷方式?不是快捷方式的文件全部删除。
作者: smss    时间: 2021-2-18 12:51

  1. for /f "delims=" %%i in ('dir /a-d/s/b * ^|findstr /V .lnk')do del "%%i"
复制代码

作者: Batcher    时间: 2021-2-18 14:14

回复 2# smss


    删除文件的代码还是判断一下路径比较好,否则可能会误删文件。
作者: Batcher    时间: 2021-2-18 14:23

回复 1# 1078292299
  1. @echo off
  2. if exist "%userprofile%\desktop\" (
  3.     cd /d "%userprofile%\desktop\"
  4. ) else if exist "%userprofile%\桌面\" (
  5.     cd /d "%userprofile%\桌面\"
  6. ) else (
  7.     goto :eof
  8. )
  9. for /f "delims=" %%i in ('dir /b /s /a-d ^| findstr /v "\.lnk$ \.url$"') do (
  10.     echo del /f /q "%%i"
  11. )
  12. pause
复制代码
如果显示结果没有问题,把倒数第三行的 echo 删掉再执行。

请参考Q-04把bat文件保存为ANSI编码:
https://mp.weixin.qq.com/s/6lbb97qUOs1sTyKJfN0ZEQ
作者: 1078292299    时间: 2021-2-18 16:44

回复 4# Batcher

如果桌面有文件夹,批处理会进入文件夹继续删里面的文件。

能不能别让批处理进入文件夹里删?
作者: Batcher    时间: 2021-2-18 16:55

回复 5# 1078292299


    把第9行的 /s 去掉
作者: 1078292299    时间: 2021-2-18 17:03

回复 6# Batcher

感谢管理员的帮助,谢谢!




欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2