cmd – For command not working using Findstr


I'm trying to run the for command at the command prompt to delete all my files that have the text "< cd_comiss>P< /cd_comiss>" , assigning them to a variable %%e , but it returns that:

%e was unexpected this time

can anybody help me?

Note: I'm browsing to the folder I want and then run the command:

for /f %%e in ('findstr "<cd_comiss>P</cd_comiss>" *.*') do del %%e


For the way you want to run, just change the way you are using the variable, instead of using %%e use %e :

for /f %e in ('findstr "<cd_comiss>P</cd_comiss>" *.*') do del %e

Just to clarify, variable usage is different when you want to run directly from Prompt or run a batch file.

When running directly from the prompt use: %e
As per batch file, use: %%e

As per the documentation, in free translation:

{% Variable | %% variable}: Required. Represents a replaceable parameter. Use the % variable to run from the command prompt. Use the %% variable to run the for command inside a batch file. Variables are case sensitive and must be represented with an alpha value such as %A, %B, or %C.

See the documentation here .

Scroll to Top