delete exe files and exclude one

4

I'm creating a bat to remove all .exe files from my desktop and downloads folder (which sometimes accumulate from so many downloads) ...

call:delfiles "*.exe"
exit

:: funcion delfiles
@echo off
pause
goto:eof
:delfiles
 set delfiles=%1
  attrib -h -s -r +a "%USERPROFILE%\Downloads\%delfiles%"
  attrib -h -s -r +a "%USERPROFILE%\Desktop\%delfiles%"
  del /f /q "%USERPROFILE%\Downloads\%delfiles%"
  del /f /q "%USERPROFILE%\Desktop\%delfiles%"
 goto:eof

But I need to exclude just one "example.exe" located in these folders. How can I do it?

But I need to exclude one "example.exe" located in these folders. How can I do it?

    
asked by ajcg 27.10.2016 в 16:03
source

2 answers

2

You can try to hide that file and after deleting it uncover it

 ....

 :delfiles
 set delfiles=%1
 attrib -h -s -r +a "%USERPROFILE%\Downloads\%delfiles%"
 attrib -h -s -r +a "%USERPROFILE%\Desktop\%delfiles%"

 ATTRIB +H  tu-ruta/ejemplo.exe
 del /f /q "%USERPROFILE%\Downloads\%delfiles%"
 del /f /q "%USERPROFILE%\Desktop\%delfiles%"
 ATTRIB -H  tu-ruta/ejemplo.exe

 goto:eof

 ....

Note: make a copy first just in case

    
answered by 27.10.2016 / 16:08
source
3

You can occupy

for %i in (*) do if not %i == ejemplo.exe del %i

Where% i is the name of each file that iterates and we compare it with the one you DO NOT want to delete

EDIT

Now I get it to work on a .bat

for %%i in (%USERPROFILE%\Downloads\%delfiles%) do if /i not "%%~nxi"=="ejemplo.exe" del "%%i"
    
answered by 27.10.2016 в 16:14