Batch command 'for' is not working -


i have following line:

for %i in (bin\setup) if not %i == setup.exe del %i 

this pretends delete files in bin\setup except 1 called setup.exe, it's not working...

any ideas on i'm doing wrong?

for %i in ("bin\setup\*") if /i not "%~nxi"=="setup.exe" echo del "%~fi" 

changes made:

  • wildcard included enumerate files in folder.
  • if case insensitive (/i)
  • file references quoted avoid problems spaces
  • only name , extension of file (%~nxi) tested. can execute for /? retrieve full list of modifiers available.
  • removal of file uses full path (%~fi) it

this written executed command line. inside batch file percent signs need escaped, replacing % %%

for %%i in ("bin\setup\*") if /i not "%%~nxi"=="setup.exe" echo del "%%~fi" 

del commands prefixed echo files not removed, command echoed console. if output correct, remove echo.


Comments

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -