Alex Rivera | Logout

Batch file: file mask

Asked 2010-07-24T16:59:47.247
9

I couldn't find details about how to use file mask in a batch file. My requirement,

forfiles -p "C:\what\ever" -s -m *.log  -c "cmd /c somecommmand"

instead of selecting all the log files (*.log), how to select all the log files which has an integer suffix at the end. Eg, Among the following files,

test.log, test1.log, test2.log, test3.log.. 

I need a file mask to select all except test.log

I tried test*.log, but that slects test.log as well. It is preferrable to not include the file name part (test). something like, *<0-9d>.log .

thanks.

Edit
Report

1 Answer

2

You could try the following, which I personally think is terrible, but it may just be what you need:

FOR %i IN (1 2 3 4 5 6 7 8 9 10 11 12 13 ...) DO IF EXIST test%i.log (somecommand)

If the suffix is really any integer number in a potentially very large range, this won't work — unless you nest several FOR loops, where each takes care of only one digit, and you change the IF EXIST test%i.log to something like IF EXIST test%a%b%c%d.log (for four digits).

Also, there's no need to execute somecommand in a separate shell (CMD /C), unless of course that is in fact what you need to do.

answered 2010-07-24T18:54:40.350

Your Answer