简体   繁体   English

Windows批处理文件删除桌面上的所有文件

[英]Windows batch file to delete all files on desktop

I'm looking to write a batch file that will remove all files on my computers desktop except for folders and .lnk (shortcut files) 我正在寻找一个批处理文件,该文件将删除计算机桌面上除文件夹和.lnk(快捷文件)以外的所有文件

The reason being that I want to run this batch file to remove all files on our meeting room PC so it's kept nice and tidy. 原因是我要运行此批处理文件以删除会议室PC上的所有文件,因此它保持整洁。

@Echo OFF

For %%# in (
    "%USERPROFILE%\Desktop\*"
) Do (
    If /I not "%%~x#" EQU ".lnk" (
        Del /Q "%%#"
    )
)

Pause&Exit
@Echo OFF

For /f "tokens=*" %%I in ('dir /s /b /a:-d-h  "%USERPROFILE%\Desktop\*"') Do (
    call :delIfNotLnk "%%I"
)
goto :EOF

:delIfNotLnk 
if  not "%~x1" == ".lnk" (
        Del /Q %1
)
goto :EOF

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM