-1

I am working on a script in batch for deleting files from all directories on my computer. I have the basics laid out, but I've run into an issue. I will put my code below.

But what is happening is that when I run the code I can't make it past the first if-statement, I inserted pauses after each line so I could find out where the problem is and that's how I know this.

What happens when I run the code is that it runs properly, it opens a terminal window, and it prompts the user for input. Immediately after I give the input though, something with the if-statement it close the window.

Thanks in advance for all the help!

The Code


set /p choice=Please enter 1 to continue or 0 to return to menu: 
if %choice%==1 (
    pause
    Set /P inp=Please enter a file name: 
    pause
    for /f %%F in (C:\Program Files)(
        if "%%F" == "%inp%" (
        goto:remo
    )
)

(I haven't finished the code entirely yet, I'm just making sure the parts that I have made run properly.)

  • 1
    Does this answer your question? [windows batch SET inside IF not working](https://stackoverflow.com/questions/9102422/windows-batch-set-inside-if-not-working) – T3RR0R Dec 03 '21 at 15:29
  • @Squashman that doesn't quite answer my question, but I appreciate the help, also if my question needs rephrasing to make it easier to understand just tell me. :) – SentBySunlight Dec 03 '21 at 16:29
  • @T3RR0R That doesn't quite answer my question either, but i appreciate the help none the less. – SentBySunlight Dec 03 '21 at 16:30

1 Answers1

1

a for loop to find a single file? Also, for these types of menus, rather use the choice command and use the errorlevel Here we test if the file exists in "C:\Program Files\" instead of for looping through it:

@echo off
echo ~~~~~~~~~~~~~~
echo Program Delete
echo ~~~~~~~~~~~~~~
choice /c 12 /m "1. Continue 2. Goto menu
goto :opt%errorlevel%

:opt1
:: Delete option is option 1 or %errorlevel% of 1
Set /P inp=Please enter a file name: 
if exist "C:\Program Files\%inp%" call :remo

:opt2
::Menu goes under option 2 or %errorlevel% of 2
Gerhard
  • 22,678
  • 7
  • 27
  • 43