# Windows Batch File Wildcards



## noyzy (May 17, 2008)

Does windows have any wildcards like linux's square bracket (e.g. [-]) wildcards?

What I want to do is a simple delete command like in the following scenerio:

Files:

Backup_Full.Bak
Backup_Full2.Bak
Backup_Full3.Bak
Backup_Full4.Bak
Backup_Full5.Bak
Backup_Full6.Bak
Backup_Full7.Bak
Backup_Full8.Bak
Backup_Full9.Bak

I want to delete files Backup_Full2.Bak through to Backup_Full9.Bak

In Linux I would use rm Backup_Full[2-9].Bak

How do I do this in windows?

I have tried:
del Backup_Full*.Bak
and
del Backup_Full?.Bak

But they both delete all the files as the wildcards also include "nothing" as their char substitute, therefore picking up the initial backup file and deleting it.

Maybe there is a way I can use a for loop? but syntax like the following does not seem possible with windows batch files?

Like 
for($i=2;$i<10;$i++)
{
del Backup_Full$i.Bak
}

Is there an alternative?


Regards

Noyzy


----------



## rthomp8363 (Aug 27, 2008)

down and dirty 
For %i in (1,1,5) do del backup%1.bak
would delete all backup files from 1 to 5

FOR /L %variable IN (start,step,end) DO command [command-parameters]

The set is a sequence of numbers from start to end, by step amount. So (1,1,5) would generate the sequence 1 2 3 4 5 and (5,-1,1) would generate the sequence (5 4 3 2 1)

FOR /F ["options"] %variable IN (file-set) DO command [command-parameters]
FOR /F ["options"] %variable IN ("string") DO command [command-parameters]
FOR /F ["options"] %variable IN ('command') DO command [command-parameters

got this information from http://www.computerhope.com/forhlp.htm


----------



## rthomp8363 (Aug 27, 2008)

for /L %i IN (1,1,5) do del backup%i.bak
Sorry, this is the right syntax


----------



## rthomp8363 (Aug 27, 2008)

for /L %%i IN (%1,1,%2) do IF EXIST backup%%i.bak del backup%%i.bak

%1 and %2 are passed on the command like from a batch program. Ex. Test 1 6, would delete all files from backup1.bak to backup6.bak

Hope this help


----------

