简体   繁体   中英

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)

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.

@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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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