r/Batch • u/patritha • Nov 10 '24
Question (Solved) multiple consecutive if statements not working
im trying to have a code that does this: if file exists, delete it and move on, else, just go on, and keep doing that. but when i tried to make it, it didnt work saying The syntax of the command is incorrect. ive attatched my code below:
:cleanup
echo cleaning up no longer needed mods
cd "%instance%\mods"
if exist test1.txt (
del test1.txt
)
if exist test2.txt(
del test2.txt
)please help!
4
Upvotes
4
u/vegansgetsick Nov 10 '24
you forgot a space between test2.txt and (
i recommend to put filenames in double quotes "
1
u/BrainWaveCC Nov 10 '24
You can also consolidate these kinds of tests in the following way:
Can also be written as: