Articles about the DOS "for" command
Sometimes I need to import file information into SQL Server, or just get a list of files, sizes, etc. Normally I use the dir command, but it generates a fixed layout that is sometimes difficult to parse. Here's an easier way to get file name, size, and date in a comma-delimited format:
for %a in (*.*) do @echo %a,%~za,%~ta...or...for %a in (*.*) do @echo %a,%~za,%~tam
Depending on which version of Windows you're running, you may prefer the 2nd version, it will add an "m" to the time display so that times show as "AM" or "PM". Windows 2003 would use the...
This is Part 2 of the series on the for command. In an earlier article I covered using for to deploy SQL scripts against multiple servers. I'm going to enhance this a little by specifying multiple databases as well, and generating server and database lists automatically. I'll also add a little enhancement for deploying scripts in a particular order of execution.
In the previous article I created a text file (servers.txt) that contained the names of the SQL Servers against which a number of scripts needed to be deployed. The assumption was that there was only a single database (with...
I've already posted an example in a previous article, and I'm going to post a couple more on neat things you can do with the DOS for command.
I recently helped out a friend with a method to deploy stored procedures to multiple servers. Previously he was generating the scripts and running them manually in Query Analyzer, for up to 8 different servers. Getting bored and making mistakes, plus needing it to be foolproof for others to use, he was looking for a better way. Here it is. :)
The for command can enumerate through file contents as well as...