The lost art of batch files

time to read 1 min | 82 words

Here is a quick & dirty way to execute a command on all the files in a directory.

for %f in (*.sql) do sqlcmd -E -S . -d DataBase_Name  < %f > %f.log

In this case, I execute all the sql files in a directory and write the results to a log.

This is useful if you've a common set of scripts that you need to run. I'm using it to get results of short operations.

Why short? Well, this is for the next post.