views:

34

answers:

1

Hello

I have a DOS batch file that performs an action for files beginning with text "SP", as follows:

FOR /F "tokens=*" %%A IN ( 'DIR SP*.sql /s /b' ) DO ECHO .compile_file = "%%A" >> output.txt

The key bit here is obviously:

DIR SP*.sql /s /b

I need to do a similar thing before the "FOR" line above, but for all other files not starting with SP*.sql

Something like:

FOR /F "tokens=*" %%A IN ( 'DIR [^SP]*.sql /s /b' ) DO ECHO .run_file = "%%A" >> output.txt
FOR /F "tokens=*" %%A IN ( 'DIR SP*.sql /s /b' ) DO ECHO .compile_file = "%%A" >> output.txt

Does anyone know how I can do this? Can I use regex for this sort of thing?

The batch file will run under CMD in Windows XP.

Cheers

+1  A: 

In batch, usually you can use findstr with /V to negate regex , eg

.... | findstr /V "^SPL"

try passing the filename to findstr and see how it goes

%~nI        - expands %I to a file name only
ghostdog74