windows - Delete all but one file loop with bat script -
i have loop in batch file delete 1 file in directory (windows 7). hangs because still sends commands screen, though i'd thought i'd suppressed it. here command i'm using:
for %i in (*) if not %i == update.bat del /s %i >nul 2>&1
tested batch script, log shows stops right @ command. tested command @ command line, outputs "del /s file.ext >nul 2>&1" command prompt each file in directory, causes batch file hang.
what need change here?
if directly in open cmd window , not batch,
can suppres output of current command leading @
sign.
@for %i in (*) @if /i not "%i"=="update.bat" @del "%i" >nul 2>&1
in batch toggle output of commands @echo off
, double %
signs of variable.
@echo off %%i in (*) if /i not "%%i"=="%~nx0" del "%%i" >nul 2>&1
Comments
Post a Comment