BoardBabe Posted November 16, 2005 Share Posted November 16, 2005 I'd like to delete all *.bmp files in %WinDir% but boot.bmp in my cleanup.cmd.whats the best way to do this? Link to comment Share on other sites More sharing options...
gosherm Posted November 16, 2005 Share Posted November 16, 2005 (edited) REN %WinDir%\boot.bmp boot.pmbdel %WinDir%\*.bmp /F /QREN %WinDir%\boot.pmb boot.bmpIt's cheap, but you'll be able to figure out what's going on when you look at it again a year from now Edited November 16, 2005 by gosherm Link to comment Share on other sites More sharing options...
BoardBabe Posted November 16, 2005 Author Share Posted November 16, 2005 lol yeh that's a cheap way of doing it.. anyone else? Link to comment Share on other sites More sharing options...
oioldman Posted November 16, 2005 Share Posted November 16, 2005 @gosherm, exactly they way my head was going with that. Link to comment Share on other sites More sharing options...
gosherm Posted November 16, 2005 Share Posted November 16, 2005 (edited) Ok, how about this?for /F "usebackq" %%i in (`dir /b %WinDir%\*.bmp`) do ( if %%i equ boot.bmp ( REM Found boot.bmp ) else ( del /f /q %%i ))My suggestion is to still use the first solution as1) it is cleaner and2) it has less overheadEdit:Hmm... I suppose this could actually be simplified a little bit to:for /F "usebackq" %%i in (`dir /b %WinDir%\*.bmp`) do ( if %%i neq boot.bmp ( del /f /q %%i )) Edited November 16, 2005 by gosherm Link to comment Share on other sites More sharing options...
BoardBabe Posted November 16, 2005 Author Share Posted November 16, 2005 Your last example there seems to be more like what im looking for. Link to comment Share on other sites More sharing options...
gosherm Posted November 16, 2005 Share Posted November 16, 2005 Glad I could be of service Link to comment Share on other sites More sharing options...
BoardBabe Posted November 16, 2005 Author Share Posted November 16, 2005 (edited) Now how about if there are TWO files i'd not like to delete. (Just for learning how this works...)eg. boot1.bmp and boot2.bmpOh.. and it did'nt work It searched for the file in the location where the batch were executed.I put a testbatch on C:\ and the result wereC:\>test2.cmdFinner ikke C:\BlåFinner ikke C:\Bobler.bmpFinner ikke C:\Fjær.bmpFinner ikke C:\Fluefisker.bmFinner ikke C:\Jade.bmpFinner ikke C:\Kaffekopp.bmpFinner ikke C:\Pastell.bmpFinner ikke C:\Rododendron.bFinner ikke C:\SantaFinner ikke C:\StormFinner ikke C:\Ullteppe.bmp Edited November 16, 2005 by BoardBabe Link to comment Share on other sites More sharing options...
gosherm Posted November 16, 2005 Share Posted November 16, 2005 (edited) %windir% is going to be your windows folder (i.e. c:\windows), not the drive root (%systemdrive%). It shouldn't have removed any files from C:\.As far as multiple files, this is where the second solution gets messy because the IF statement can't handle complex statements (i.e. if (a=b OR a=c) then). So, you're left with:for /F "usebackq" %%i in (`dir /b %WinDir%\*.bmp`) do ( if %%i neq boot.bmp ( if %%i neq boot2.bmp ( del /f /q %%i ) ))Whereas the first solution gives you:REN %WinDir%\boot.bmp boot.pmbREN %WinDir%\boot2.bmp boot2.pmbdel %WinDir%\*.bmp /F /QREN %WinDir%\boot.pmb boot.bmpREN %WinDir%\boot2.pmb boot2.bmp Edited November 16, 2005 by gosherm Link to comment Share on other sites More sharing options...
BoardBabe Posted November 16, 2005 Author Share Posted November 16, 2005 Hmm recheck that script, cause it deletes boot.bmp also Link to comment Share on other sites More sharing options...
gosherm Posted November 16, 2005 Share Posted November 16, 2005 Hmm... it shouldn't be... though I did find one problem.Try this as a test:for /F "usebackq tokens=*" %%i in (`dir /b %WinDir%\*.bmp`) do ( if %%i neq boot.bmp ( if %%i neq boot2.bmp ( echo deleting "%%i" ) else ( echo saving "%%i" ) ) else ( echo saving "%%i" ))and this as the final:for /F "usebackq tokens=*" %%i in (`dir /b %WinDir%\*.bmp`) do ( if %%i neq boot.bmp ( if %%i neq boot2.bmp ( del /f /q "%%i" ) )) Link to comment Share on other sites More sharing options...
BoardBabe Posted November 17, 2005 Author Share Posted November 17, 2005 Now it does exclude boot.bmp, but it's still something wrong with the path. I put this in test.cmd on c:\ and the result of #2 is (translated):Could not find C:\Jade.bmpCould not find C:\Pastell.bmpetc.Maybe it should be del /f /q "%WinDir%\%%i"? Link to comment Share on other sites More sharing options...
gosherm Posted November 17, 2005 Share Posted November 17, 2005 Doh! I think you're right... I can't believe I missed that. Link to comment Share on other sites More sharing options...
BoardBabe Posted November 17, 2005 Author Share Posted November 17, 2005 (edited) Hehe I was Thank's for the help!PS. the (del) /f is not needed as the files are not write protected. Edited November 17, 2005 by BoardBabe Link to comment Share on other sites More sharing options...
BoardBabe Posted November 19, 2005 Author Share Posted November 19, 2005 (edited) This seems to work alsofor /f "usebackq tokens=*" %%i in (`dir /b "%winDir%\*.bmp"`) do if %%i neq boot.bmp del /q "%WinDir%\%%i" Edited November 19, 2005 by BoardBabe Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now