RKB83
RKB83

Reputation: 83

Using variable in Windows FOR Loop

What I'm trying to achieve is to take a user input which would be a term with numbers and letters and then use that to match directories in a folder and delete ones matching, here's what i have till now, but its not working,

@echo off
set /p:ID=Enter Search Term:
for /d %%G in ("*(%ID%)") do rd /s /q "%%~G"
pause

The output that i get if i turn on echo shows, that %ID% is not getting replaced with variable value which was the prompted input. Following is the output

for / %G in ("*()") do rd /s /q "%~G"

Can someone point out the error in this? thanks a lot

Upvotes: 1

Views: 43

Answers (1)

MC ND
MC ND

Reputation: 70923

set /p:ID=Enter Search Term:
      ^ This colon is included in the name of the variable

So, you end with a variable named :ID. You can execute set : to see the variable defined.

To solve the problem just remove the colon.

set /p ID=Enter Search Term:

Upvotes: 4

Related Questions