<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Mark Yocom's Script Tips</title><link>http://blogs.msdn.com/myocom/default.aspx</link><description>Scripting tips, covering batch, VBScript, and the occasional Perl script.</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Windows command line references</title><link>http://blogs.msdn.com/myocom/archive/2008/01/28/windows-command-line-references.aspx</link><pubDate>Tue, 29 Jan 2008 01:32:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7294197</guid><dc:creator>myocom</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/myocom/comments/7294197.aspx</comments><wfw:commentRss>http://blogs.msdn.com/myocom/commentrss.aspx?PostID=7294197</wfw:commentRss><description>&lt;P&gt;&lt;FONT face=Verdana size=2&gt;I found that TechNet has references for the Windows command line utilities.&amp;nbsp; Much of these are just a rehash of the help you'd get with /? but at least they're easier to read...&lt;/P&gt;
&lt;P&gt;&lt;A class="" href="http://technet2.microsoft.com/windowsserver/en/library/552ed70a-208d-48c4-8da8-2e27b530eac71033.mspx?mfr=true" target=_blank mce_href="http://technet2.microsoft.com/windowsserver/en/library/552ed70a-208d-48c4-8da8-2e27b530eac71033.mspx?mfr=true"&gt;This&lt;/A&gt; is a list of commands for Windows Server 2003 (most apply to Windows XP as well), and&amp;nbsp;&lt;A class="" href="http://technet2.microsoft.com/windowsserver2008/en/library/69baa34b-d4b3-40ec-bd2f-12d98f7802d51033.mspx?mfr=true" target=_blank mce_href="http://technet2.microsoft.com/windowsserver2008/en/library/69baa34b-d4b3-40ec-bd2f-12d98f7802d51033.mspx?mfr=true"&gt;here&lt;/A&gt; is the list for Vista and Server 2008.&lt;/FONT&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=7294197" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/myocom/archive/tags/Resources/default.aspx">Resources</category><category domain="http://blogs.msdn.com/myocom/archive/tags/Batch/default.aspx">Batch</category></item><item><title>On blogging tools</title><link>http://blogs.msdn.com/myocom/archive/2006/08/25/on-blogging-tools.aspx</link><pubDate>Sat, 26 Aug 2006 07:02:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:724940</guid><dc:creator>myocom</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/myocom/comments/724940.aspx</comments><wfw:commentRss>http://blogs.msdn.com/myocom/commentrss.aspx?PostID=724940</wfw:commentRss><description>&lt;P&gt;One of the obstacles to frequent posting (at least mine) is that the types of posts I typically make include code.&amp;nbsp; Code that I would like to be formatted nicely.&amp;nbsp; Unfortunately, this previously meant hand-crafting HTML to make it all look nice.&amp;nbsp; In some cases, I could write up scripts in Visual Studio and paste them into an editor which would (mostly) preserve the formatting, but having to write batch files in VS seems hugely overkill.&amp;nbsp; Anyway, since that was such a pain, I didn't post often.&lt;/P&gt;
&lt;P&gt;Enter &lt;A href="http://windowslivewriter.spaces.live.com/" target=_blank mce_href="http://windowslivewriter.spaces.live.com/"&gt;Windows Live Writer&lt;/A&gt;.&amp;nbsp; Everyone else is blogging about it, so hey, why shouldn't I?&amp;nbsp; Out of the box, it's very, very nice (and free, to boot!).&amp;nbsp; It's a truly WYSIWYG editor (not the typical WYSI-more or less-WYG-with a few little problems here and there) and that handles all of my typical blogging needs.&amp;nbsp; &lt;EM&gt;Except&lt;/EM&gt; the whole code formatting thing.&amp;nbsp; Aha, you say, how does that help?&amp;nbsp; &lt;/P&gt;
&lt;P&gt;Easy.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;WLW supports plugins, and they're (evidently) easy to develop.&amp;nbsp; Even though it's still in beta, there are dozens of plugins already.&amp;nbsp; A few of those plugins enable code formatting.&amp;nbsp; I've chosen to use Steve Dunn's cleverly named &lt;A href="http://stevedunns.blogspot.com/2006/08/code-formatter-plugin-for-windows-live.html" target=_blank mce_href="http://stevedunns.blogspot.com/2006/08/code-formatter-plugin-for-windows-live.html"&gt;Code Formatter Plugin&lt;/A&gt;, which uses Actipro's &lt;A href="http://www.actiprosoftware.com/Products/DotNet/CodeHighlighter/Default.aspx" target=_blank mce_href="http://www.actiprosoftware.com/Products/DotNet/CodeHighlighter/Default.aspx"&gt;CodeHighlighter&lt;/A&gt; web control.&amp;nbsp; Most of the code highlighters out there only seem to support the Visual Studio types of code (your C, your VB.Net, etc.).&amp;nbsp; Try to get scripts highlighted and forget about it.&amp;nbsp; This one does, though, and even though it's not &lt;EM&gt;quite&lt;/EM&gt; the same style of highlighting I'm used to, it's way better than nothing.&lt;/P&gt;
&lt;P&gt;Take the scriptlet I wrote in&amp;nbsp;&lt;A href="https://blogs.msdn.com/myocom/archive/2005/06/03/425046.aspx" target=_blank mce_href="https://blogs.msdn.com/myocom/archive/2005/06/03/425046.aspx"&gt;this post&lt;/A&gt;.&amp;nbsp; Hand-styling that was a huge pain, and all I really did was keep the indenting and ensure it was all in a fixed-width font.&amp;nbsp; But all that indenting added up to a lot of &amp;amp;nbsp;'s and it was easy to lose track of how many I'd already done.&lt;/P&gt;
&lt;P&gt;With this plugin to WLW, though, it's a matter of clicking "Insert Formatted Code" or "Insert Clipboard as Code" and you get this instead:&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV class=wlWriterSmartContent id=57F11A72-B0E5-49c7-9094-E3A15BD5B5E7:28c2175f-f606-4528-9f8f-3675826f243e contentEditable=false style="PADDING-RIGHT: 0px; DISPLAY: inline; PADDING-LEFT: 0px; FLOAT: none; PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-TOP: 0px"&gt;&lt;PRE style="BACKGROUND-COLOR: white"&gt;&lt;DIV&gt;&lt;!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--&gt;&lt;SPAN style="COLOR: #008080"&gt;1&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;for&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;f &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;delims=/ tokens=1-3&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; %%a in &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;%DATE:~4%&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;)&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;do&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008080"&gt;2&lt;/SPAN&gt; &lt;SPAN style="COLOR: #000000"&gt;    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;for&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;f &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;delims=:. tokens=1-4&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; %%m in &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;%TIME%&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;)&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;do&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008080"&gt;3&lt;/SPAN&gt; &lt;SPAN style="COLOR: #000000"&gt;        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;set&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; FILENAME&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;basename-%%c-%%b-%%a-%%m%%n%%o%%p
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008080"&gt;4&lt;/SPAN&gt; &lt;SPAN style="COLOR: #000000"&gt;    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;)&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008080"&gt;5&lt;/SPAN&gt; &lt;SPAN style="COLOR: #000000"&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P mce_keep="true"&gt;Line numbers and everything.&amp;nbsp; In the future, I'll skip the line numbers for bits of script I intend for people to copy and paste, but to illustrate points, I'll include them.&lt;/P&gt;
&lt;P&gt;Ok, enough rah-rah from me.&amp;nbsp; I have scripts to write.&lt;/P&gt;
&lt;P&gt;&lt;FONT size=1&gt;(But seriously.&amp;nbsp; If you blog, this is an awesome tool.)&lt;/FONT&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=724940" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/myocom/archive/tags/Resources/default.aspx">Resources</category><category domain="http://blogs.msdn.com/myocom/archive/tags/Deep+Thoughts/default.aspx">Deep Thoughts</category></item><item><title>Definitive list of illegal filenames?</title><link>http://blogs.msdn.com/myocom/archive/2006/07/11/662581.aspx</link><pubDate>Tue, 11 Jul 2006 22:11:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:662581</guid><dc:creator>myocom</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/myocom/comments/662581.aspx</comments><wfw:commentRss>http://blogs.msdn.com/myocom/commentrss.aspx?PostID=662581</wfw:commentRss><description>&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&lt;A href="http://blogs.msdn.com/myocom/archive/2005/06/08/427043.aspx"&gt;Earlier&lt;/A&gt;, I tried to come up with a definitive list of illegal filesystem names, but it seems this is already documented.&amp;nbsp; Who knew?&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.microsoft.com/Default.aspx?id=74496"&gt;&lt;FONT face=Verdana size=2&gt;http://support.microsoft.com/Default.aspx?id=74496&lt;/FONT&gt;&lt;/A&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=662581" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/myocom/archive/tags/Batch/default.aspx">Batch</category></item><item><title>More on command line redirection</title><link>http://blogs.msdn.com/myocom/archive/2006/05/17/600110.aspx</link><pubDate>Wed, 17 May 2006 20:30:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:600110</guid><dc:creator>myocom</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/myocom/comments/600110.aspx</comments><wfw:commentRss>http://blogs.msdn.com/myocom/commentrss.aspx?PostID=600110</wfw:commentRss><description>&lt;P&gt;&lt;FONT face=Verdana size=2&gt;For those of you who are more interested in the gritty details of &lt;A href="https://blogs.msdn.com/myocom/archive/2005/06/08/427043.aspx"&gt;command line redirection&lt;/A&gt;, RaymondC has posted a couple of great articles recently on his excellent &lt;A HREF="/oldnewthing"&gt;The Old New Thing&lt;/A&gt;&amp;nbsp;blog.&amp;nbsp; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;The &lt;A HREF="/oldnewthing/archive/2006/05/16/598893.aspx"&gt;first&lt;/A&gt;&amp;nbsp;discusses how (and more importantly, &lt;EM&gt;why&lt;/EM&gt;) the redirection symbols are parsed by CMD.EXE rather than the program you're calling.&amp;nbsp; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;The &lt;A HREF="/oldnewthing/archive/2006/05/17/599916.aspx"&gt;second&lt;/A&gt; points out some of the caveats of blindly accepting input from environment variables.&amp;nbsp; While it may be a pain to quote the parameters your script takes, it can make troubleshooting easier and, as his post points out, can prevent your day from being ruined.&lt;/FONT&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=600110" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/myocom/archive/tags/Batch/default.aspx">Batch</category></item><item><title>Evolution of a solution</title><link>http://blogs.msdn.com/myocom/archive/2005/09/30/475960.aspx</link><pubDate>Sat, 01 Oct 2005 08:15:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:475960</guid><dc:creator>myocom</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/myocom/comments/475960.aspx</comments><wfw:commentRss>http://blogs.msdn.com/myocom/commentrss.aspx?PostID=475960</wfw:commentRss><description>&lt;font face="Verdana" size=2&gt;The other day, someone posted a message at work asking for a way to find out the drive letter for partition 1 on the first disk.&lt;br /&gt;&lt;br /&gt;
The first response offered this:&lt;br /&gt;&lt;br /&gt;&lt;/font&gt;
&lt;font face="Courier New"&gt;C:&amp;gt;echo list volume | diskpart&lt;br /&gt;
Microsoft DiskPart version 5.1.3565&lt;br /&gt;
&lt;br /&gt;
Copyright (C) 1999-2003 Microsoft Corporation.&lt;br /&gt;
&lt;br /&gt;
On computer: SINISTAR&lt;br /&gt;
&lt;br /&gt;
DISKPART&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;Volume&amp;nbsp;###&amp;nbsp;&amp;nbsp;Ltr&amp;nbsp;&amp;nbsp;Label&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Fs&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Type&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Size&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Status&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Info&lt;br /&gt;
&amp;nbsp;&amp;nbsp;----------&amp;nbsp;&amp;nbsp;---&amp;nbsp;&amp;nbsp;-----------&amp;nbsp;&amp;nbsp;-----&amp;nbsp;&amp;nbsp;----------&amp;nbsp;&amp;nbsp;-------&amp;nbsp;&amp;nbsp;---------&amp;nbsp;&amp;nbsp;--------&lt;br /&gt;
&amp;nbsp;&amp;nbsp;Volume 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;F&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;DVD-ROM&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0 B&lt;br /&gt;
&amp;nbsp;&amp;nbsp;Volume 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;C&amp;nbsp;&amp;nbsp;&amp;nbsp;BOOTDRIVE&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FAT32&amp;nbsp;&amp;nbsp;Partition&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;9 GB&amp;nbsp;&amp;nbsp;Healthy&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;System&lt;br /&gt;
&amp;nbsp;&amp;nbsp;Volume 2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;D&amp;nbsp;&amp;nbsp;&amp;nbsp;Application&amp;nbsp;&amp;nbsp;NTFS&amp;nbsp;&amp;nbsp;&amp;nbsp;Partition&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;15 GB&amp;nbsp;&amp;nbsp;Healthy&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Pagefile&lt;br /&gt;
&amp;nbsp;&amp;nbsp;Volume 3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;E&amp;nbsp;&amp;nbsp;&amp;nbsp;SharedAndUn&amp;nbsp;&amp;nbsp;NTFS&amp;nbsp;&amp;nbsp;&amp;nbsp;Partition&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;10 GB&amp;nbsp;&amp;nbsp;Healthy&lt;br /&gt;
&lt;br /&gt;
DISKPART&amp;gt;&lt;br /&gt;
&lt;br /&gt;
C:\&amp;gt;&lt;br/&gt;&lt;br /&gt;&lt;/font&gt;
&lt;font face="Verdana" size=2&gt;The original poster then asked if anyone already had a script to parse the output of diskpart.  I helpfully offered this:&lt;br /&gt;&lt;br /&gt;&lt;/font&gt;
&lt;font face="Courier New" size=2&gt;@for /f "tokens=3" %%x in ('echo list volume ^| diskpart ^| findstr /c:"Volume %1"') do @echo %%x&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;
&lt;font face="Verdana" size=2&gt;"How clever of me," thought I.  "Simply pass in a volume number and it neatly spits out the drive letter."  I was all proud of myself until someone pointed out that we already had a perfectly good .exe that did the same thing.&lt;br /&gt;
&lt;br /&gt;
The moral?  It's all fun and games 'til you find out you just reinvented the wheel...&lt;/font&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=475960" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/myocom/archive/tags/Batch/default.aspx">Batch</category></item><item><title>Making your scripts look prettier</title><link>http://blogs.msdn.com/myocom/archive/2005/09/30/475957.aspx</link><pubDate>Sat, 01 Oct 2005 06:48:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:475957</guid><dc:creator>myocom</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/myocom/comments/475957.aspx</comments><wfw:commentRss>http://blogs.msdn.com/myocom/commentrss.aspx?PostID=475957</wfw:commentRss><description>&lt;FONT face=Verdana size=2&gt;Many languages provide a mechanism to make their code look pretty. VBScript, for example, assumes one statement per line, but including an underscore at the end of the line indicates that your statement continues on the next line.&lt;BR&gt;&lt;BR&gt;&lt;U&gt;Normal&lt;/U&gt;&lt;/FONT&gt;&lt;BR&gt;&lt;FONT face="Courier New" size=2&gt;WScript.Echo "This is line one" &amp;amp; vbcrlf&amp;nbsp;&amp;amp; "This is line two" &amp;amp; vbcrlf &amp;amp; "This is line three"&lt;/FONT&gt;&lt;BR&gt;&lt;BR&gt;&lt;FONT face=Verdana size=2&gt;&lt;U&gt;With Line Continuation Characters&lt;/U&gt;&lt;/FONT&gt;&lt;BR&gt;&lt;FONT face="Courier New" size=2&gt;WScript.Echo "This is line one" &amp;amp; vbcrlf &amp;amp; _ &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "This is line two" &amp;amp; vbcrlf &amp;amp; _&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "This is line three"&lt;BR&gt;&lt;BR&gt;&lt;/font&gt;&lt;FONT face=Verdana size=2&gt;It's much easier to tell what's going on in the second script.&lt;BR&gt;&lt;BR&gt;In batch, you often see variables "built up" like this:&lt;/FONT&gt;&lt;BR&gt;&lt;BR&gt;&lt;FONT face="Courier New" size=2&gt;set MACHINENAMES=sinistar&lt;BR&gt;set MACHINENAMES=%MACHINENAMES% tempest&lt;BR&gt;set MACHINENAMES=%MACHINENAMES% joust&lt;/FONT&gt;&lt;BR&gt;&lt;BR&gt;&lt;FONT face=Verdana size=2&gt;...and in the end you have a variable with three items in it.&lt;BR&gt;&lt;BR&gt;As it happens,&amp;nbsp;you can take advantage of CMD's escape character, the carat, to make this a little easier to read:&lt;/FONT&gt;&lt;BR&gt;&lt;BR&gt;&lt;FONT face="Courier New" size=2&gt;set MACHINENAMES=sinistar^&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;tempest^&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;joust&lt;/FONT&gt;&lt;BR&gt;&lt;BR&gt;&lt;font face="Verdana" size=2&gt;And again you have a variable with three items in it.&amp;nbsp; The second example does have one (largish) difference, though.&amp;nbsp; Rather than &lt;FONT face="Courier New" size=2&gt;MACHINENAMES&lt;/FONT&gt; being "sinistar tempest joust" (as in the first example), it will have "sinistar&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tempest&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; joust".&amp;nbsp; If spacing is important to what you're doing, then by all means stick to the first way.&amp;nbsp; However, if you're only building up a list to use in a &lt;FONT face="Courier New" size=2&gt;for&lt;/FONT&gt; loop, the second will work just fine since &lt;FONT face="Courier New" size=2&gt;for&lt;/FONT&gt; splits its arguments on one or more whitespace characters, so the following are equivalent:&lt;BR&gt;&lt;BR&gt;&lt;FONT face="Courier New" size=2&gt;for %x in (%MACHINENAMES%) do @echo %x&lt;BR&gt;for %x in (sinistar tempest joust) do @echo %x&lt;BR&gt;for %x in (sinistar&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;tempest&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;joust) do @echo %x&lt;/FONT&gt;&lt;BR&gt;&lt;BR&gt;Admittedly, I've only used this once or twice. Generally the lists I have to keep are pretty small, but on the occasions where I have very long lists, it can come in handy.&lt;/FONT&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=475957" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/myocom/archive/tags/Batch/default.aspx">Batch</category><category domain="http://blogs.msdn.com/myocom/archive/tags/VBScript/default.aspx">VBScript</category></item><item><title>That's a pretty shifty argument...</title><link>http://blogs.msdn.com/myocom/archive/2005/06/30/434360.aspx</link><pubDate>Thu, 30 Jun 2005 23:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:434360</guid><dc:creator>myocom</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/myocom/comments/434360.aspx</comments><wfw:commentRss>http://blogs.msdn.com/myocom/commentrss.aspx?PostID=434360</wfw:commentRss><description>&lt;P&gt;&lt;FONT face=Verdana size=2&gt;It's pretty easy to deal with up to 9 arguments in batch through built-in variables &lt;FONT face="Courier New"&gt;%1&lt;/FONT&gt; through &lt;FONT face="Courier New"&gt;%9&lt;/FONT&gt;.&amp;nbsp; For &lt;/FONT&gt;&lt;FONT face=Verdana size=2&gt;example:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;U&gt;echoargs.cmd&lt;/U&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @echo off&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; echo %1&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; echo %2&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; echo %3&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; echo %4&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; echo %5&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; echo %6&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; echo %7&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; echo %8&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; echo %9&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;If you feed this A B C D E F G H I, you'll get back those letters, one per line.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;But, if you try this with a tenth argument, it won't work like you might have thought:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;U&gt;echo10args.cmd&lt;BR&gt;&lt;/U&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @echo off&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; echo %1&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; echo %2&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; echo %3&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; echo %4&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; echo %5&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; echo %6&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; echo %7&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; echo %8&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; echo %9&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; echo %10&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;You'll see that the last line echoes the first argument again, followed by a 0 (&lt;FONT face="Courier New"&gt;A0&lt;/FONT&gt;).&amp;nbsp; That is, it gets parsed as &lt;/FONT&gt;&lt;FONT face=Verdana size=2&gt;"echo %1, then 0".&amp;nbsp; So, how do you deal with this if you need more than 9 arguments?&amp;nbsp; My first suggestion &lt;/FONT&gt;&lt;FONT face=Verdana size=2&gt;would be to see if there's a way you can deal with fewer arguments, though that's often not possible.&amp;nbsp; If &lt;/FONT&gt;&lt;FONT face=Verdana size=2&gt;you must, you'll need to loop over each argument and deal with them one by one.&amp;nbsp; Here's an example &lt;/FONT&gt;&lt;FONT face=Verdana size=2&gt;listing:&lt;/FONT&gt;&lt;/P&gt;&lt;FONT face="Courier New" size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;U&gt;echoallargs.cmd&lt;/U&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @echo off&lt;BR&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size=2&gt;&lt;/FONT&gt;&lt;BR&gt;&lt;FONT face="Courier New" size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; :Top&lt;/FONT&gt;&lt;BR&gt;&lt;FONT face="Courier New" size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; REM If there aren't any arguments to deal with, bail out&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if "%1" equ "" goto :NoMoreArgs&lt;/FONT&gt;&lt;BR&gt;&lt;BR&gt;&lt;FONT face="Courier New" size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; call :EchoArg %1&lt;/FONT&gt;&lt;BR&gt;&lt;FONT face="Courier New" size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; shift&lt;/FONT&gt;&lt;BR&gt;&lt;BR&gt;&lt;FONT face="Courier New" size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; REM Start the loop over again with a brand new %1&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; goto :Top&lt;/FONT&gt;&lt;BR&gt;&lt;BR&gt;&lt;FONT face="Courier New" size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; :NoMoreArgs&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; echo No more arguments to deal with&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; goto :EOF&lt;/FONT&gt;&lt;BR&gt;&lt;BR&gt;&lt;FONT face="Courier New" size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; :EchoArg&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; echo Arg: %1&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; goto :EOF&lt;/FONT&gt;&lt;BR&gt;&lt;BR&gt;&lt;FONT face=Verdana size=2&gt;Let's call this script with 11 arguments: &lt;FONT face="Courier New"&gt;A B C D E F G H I J K&lt;/FONT&gt;&lt;/FONT&gt; 
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;At &lt;FONT face="Courier New"&gt;:Top&lt;/FONT&gt;, we check to see if there are any arguments to deal with.&amp;nbsp; If not, we go to :NoMoreArgs and bail &lt;/FONT&gt;&lt;FONT face=Verdana size=2&gt;out.&amp;nbsp; Then (assuming we didn't bail out), we call &lt;FONT face="Courier New"&gt;:EchoArg&lt;/FONT&gt; with the parameter that's first in the list (in &lt;/FONT&gt;&lt;FONT face=Verdana size=2&gt;this case, &lt;FONT face="Courier New"&gt;A&lt;/FONT&gt;).&amp;nbsp; &lt;FONT face="Courier New"&gt;:EchoArg&lt;/FONT&gt; takes the parameter it was passed (&lt;FONT face="Courier New"&gt;A&lt;/FONT&gt;) and echos &lt;FONT face="Courier New"&gt;Arg: A&lt;/FONT&gt;.&amp;nbsp; Once it's done, we use &lt;/FONT&gt;&lt;FONT face=Verdana size=2&gt;&lt;FONT face="Courier New"&gt;goto :EOF&lt;/FONT&gt; to indicate that we're done with this subroutine.&amp;nbsp; Control then passes back up to the line &lt;/FONT&gt;&lt;FONT face=Verdana size=2&gt;just after our &lt;FONT face="Courier New"&gt;call&lt;/FONT&gt;.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;This next step is where all the magic happens.&amp;nbsp; The &lt;FONT face="Courier New"&gt;shift&lt;/FONT&gt; command takes everything you've passed in and &lt;/FONT&gt;&lt;FONT face=Verdana size=2&gt;shifts them all to the left by one.&amp;nbsp; That is, what used to be &lt;FONT face="Courier New"&gt;%3&lt;/FONT&gt; becomes &lt;FONT face="Courier New"&gt;%2&lt;/FONT&gt;, &lt;FONT face="Courier New"&gt;%2&lt;/FONT&gt; becomes &lt;FONT face="Courier New"&gt;%1&lt;/FONT&gt;, and &lt;FONT face="Courier New"&gt;%1&lt;/FONT&gt; falls &lt;/FONT&gt;&lt;FONT face=Verdana size=2&gt;off.&amp;nbsp; So now, since there was a tenth parameter, that one becomes &lt;FONT face="Courier New"&gt;%9&lt;/FONT&gt;, which means there's now a way of &lt;/FONT&gt;&lt;FONT face=Verdana size=2&gt;referring to it.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Once we've shifted everything, we go back to the &lt;FONT face="Courier New"&gt;:Top&lt;/FONT&gt; again.&amp;nbsp; Now since our original second argument (B) &lt;/FONT&gt;&lt;FONT face=Verdana&gt;&lt;FONT size=2&gt;has been shifted to &lt;FONT face="Courier New"&gt;%1&lt;/FONT&gt;, we do the same thing all over again.&amp;nbsp; That gets echoed, we &lt;FONT face="Courier New"&gt;shift&lt;/FONT&gt; again, and &lt;FONT face="Courier New"&gt;C&lt;/FONT&gt; is &lt;/FONT&gt;&lt;FONT size=2&gt;the new &lt;FONT face="Courier New"&gt;%1&lt;/FONT&gt; (and K is the new &lt;FONT face="Courier New"&gt;%9&lt;/FONT&gt;).&amp;nbsp; We keep doing this until we run out of arguments, and then we bail out.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;There are a few important points in here:&lt;/FONT&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;FONT face=Verdana size=2&gt;For anything you call, whether it's a "subroutine" like &lt;FONT face="Courier New"&gt;:EchoArg&lt;/FONT&gt; or another script (like &lt;FONT face="Courier New"&gt;call foo.cmd&lt;/FONT&gt;), &lt;/FONT&gt;&lt;FONT face=Verdana size=2&gt;the arguments passed to it are "local".&amp;nbsp; That is, if&amp;nbsp;you were to call &lt;FONT face="Courier New"&gt;:EchoArg %8&lt;/FONT&gt; (that is, &lt;FONT face="Courier New"&gt;H&lt;/FONT&gt; in our case), &lt;/FONT&gt;&lt;FONT face=Verdana size=2&gt;as far as &lt;FONT face="Courier New"&gt;:EchoArg&lt;/FONT&gt; is concerned, that's &lt;FONT face="Courier New"&gt;%1&lt;/FONT&gt;.&amp;nbsp; It's its own first argument.&lt;/FONT&gt;&lt;FONT face=Verdana size=2&gt; 
&lt;LI&gt;The built-in variable &lt;FONT face="Courier New"&gt;%*&lt;/FONT&gt; (meaning all arguments passed in) is not at all affected by &lt;FONT face="Courier New"&gt;shift&lt;/FONT&gt;.&amp;nbsp; In our &lt;/FONT&gt;&lt;FONT face=Verdana size=2&gt;example, no matter how much you &lt;FONT face="Courier New"&gt;shift&lt;/FONT&gt;, &lt;FONT face="Courier New"&gt;%*&lt;/FONT&gt; will still be &lt;FONT face="Courier New"&gt;A B C D E F G H I J K&lt;/FONT&gt;.&amp;nbsp; This is sort of &lt;/FONT&gt;&lt;FONT face=Verdana size=2&gt;unfortunate, in my opinion, since there are times that I've found that I wanted to deal with the first &lt;/FONT&gt;&lt;FONT face=Verdana size=2&gt;(say) three arguments, then refer to "the rest" in one fell swoop, but the only way to do that is &lt;FONT face="Courier New"&gt;shift&lt;/FONT&gt; &lt;/FONT&gt;&lt;FONT face=Verdana size=2&gt;your way through them one by one.&lt;/FONT&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;While we're on the topic of &lt;FONT face="Courier New"&gt;shift&lt;/FONT&gt;, you can see from &lt;FONT face="Courier New"&gt;shift /?&lt;/FONT&gt; that it can also take a switch that indicates &lt;/FONT&gt;&lt;FONT face=Verdana size=2&gt;where you want to start shifting.&amp;nbsp; This takes a bit of wrapping your brain around, but it goes like this:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Given a list of arguments &lt;FONT face="Courier New"&gt;A B C D E F G H I J K&lt;/FONT&gt;, a regular shift would change that to &lt;FONT face="Courier New"&gt;B C D E F G H I J K&lt;/FONT&gt;. &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;But, we could also use &lt;FONT face="Courier New"&gt;shift /3&lt;/FONT&gt; (for example) to start the shifting at the third argument.&amp;nbsp; So our &lt;FONT face="Courier New"&gt;A B C D &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face=Verdana size=2&gt;&lt;FONT face="Courier New"&gt;E F G H I J K&lt;/FONT&gt; becomes &lt;FONT face="Courier New"&gt;A B D E F G H I J K&lt;/FONT&gt;; the third argument (&lt;FONT face="Courier New"&gt;C&lt;/FONT&gt;) gets swallowed.&amp;nbsp; Note that even though you &lt;/FONT&gt;&lt;FONT face=Verdana size=2&gt;can address 9 elements at a time &lt;FONT face="Courier New"&gt;%1 &lt;/FONT&gt;&lt;FONT face=Verdana&gt;through &lt;FONT face="Courier New"&gt;%9&lt;/FONT&gt;, you can't do &lt;FONT face="Courier New"&gt;shift /9&lt;/FONT&gt; and have the tenth argument become the &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face=Verdana size=2&gt;ninth.&amp;nbsp; You're limited to &lt;FONT face="Courier New"&gt;shift /8&lt;/FONT&gt;.&amp;nbsp; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Oh well, you can't have everything...&lt;/FONT&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=434360" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/myocom/archive/tags/Batch/default.aspx">Batch</category></item><item><title>Ignoring the output of a command</title><link>http://blogs.msdn.com/myocom/archive/2005/06/08/427043.aspx</link><pubDate>Thu, 09 Jun 2005 02:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:427043</guid><dc:creator>myocom</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/myocom/comments/427043.aspx</comments><wfw:commentRss>http://blogs.msdn.com/myocom/commentrss.aspx?PostID=427043</wfw:commentRss><description>&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&lt;a href="https://blogs.msdn.com:443/myocom/archive/2005/06/03/425062.aspx"&gt;Earlier&lt;/A&gt;, I used &lt;FONT face="Courier New"&gt;&amp;gt;nul 2&amp;gt;&amp;amp;1&lt;/FONT&gt; to suppress the output of a command, and the question was brought up as to why this was "better" than just &lt;FONT face="Courier New"&gt;&amp;gt;nul&lt;/FONT&gt;.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;To understand what's going on, you need to know that there are two streams of output from any given command.&amp;nbsp; There's &lt;FONT face="Courier New"&gt;STDOUT&lt;/FONT&gt; (or "standard out", or "standard output") and &lt;FONT face="Courier New"&gt;STDERR&lt;/FONT&gt; (or "standard error").&amp;nbsp; Well-behaved executables will output error messages to &lt;FONT face="Courier New"&gt;STDERR&lt;/FONT&gt; and regular output to &lt;FONT face="Courier New"&gt;STDOUT&lt;/FONT&gt;.&amp;nbsp; In &lt;FONT face="Courier New"&gt;CMD&lt;/FONT&gt; by default, both &lt;FONT face="Courier New"&gt;STDOUT&lt;/FONT&gt; and &lt;FONT face="Courier New"&gt;STDERR&lt;/FONT&gt; are echoed to the console.&amp;nbsp; You can redirect this output by using &lt;FONT face="Courier New"&gt;&amp;gt;&lt;/FONT&gt;.&amp;nbsp; Typically this is done to redirect output to a file.&amp;nbsp; However, this only redirects &lt;FONT face="Courier New"&gt;STDOUT&lt;/FONT&gt; to the file; &lt;FONT face="Courier New"&gt;STDERR&lt;/FONT&gt; will still display on the screen.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;On the command line, when redirecting output, 1 (or nothing) means &lt;FONT face="Courier New"&gt;STDOUT&lt;/FONT&gt; and 2 means &lt;FONT face="Courier New"&gt;STDERR&lt;/FONT&gt;.&amp;nbsp; That is, &lt;FONT face="Courier New"&gt;foo.exe &amp;gt;foo.txt&lt;/FONT&gt; redirects &lt;FONT face="Courier New"&gt;foo.exe&lt;/FONT&gt;'s &lt;FONT face="Courier New"&gt;STDOUT&lt;/FONT&gt; to &lt;FONT face="Courier New"&gt;foo.txt&lt;/FONT&gt;, and its &lt;FONT face="Courier New"&gt;STDERR&lt;/FONT&gt; (if any) will display on the screen.&amp;nbsp; Running &lt;FONT face="Courier New"&gt;foo.exe 1&amp;gt;foo.txt&lt;/FONT&gt; would do the same thing.&amp;nbsp; To deal with &lt;FONT face="Courier New"&gt;STDERR&lt;/FONT&gt;, use &lt;FONT face="Courier New"&gt;2&amp;gt;&lt;/FONT&gt;, as in &lt;FONT face="Courier New"&gt;foo.exe 2&amp;gt;foo.txt&lt;/FONT&gt;.&amp;nbsp; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;So, if you wanted &lt;STRONG&gt;all&lt;/STRONG&gt; output from &lt;FONT face="Courier New"&gt;foo.exe&lt;/FONT&gt;, you could run &lt;FONT face="Courier New"&gt;foo.exe &amp;gt;foo.txt 2&amp;gt;foo.txt&lt;/FONT&gt;.&amp;nbsp; As it happens, since that's a lot of typing, &lt;FONT face="Courier New"&gt;CMD&lt;/FONT&gt; has this little shortcut for tying one stream's redirection to another: &lt;FONT face="Courier New"&gt;foo.exe &amp;gt;foo.txt 2&amp;gt;&amp;amp;1&lt;/FONT&gt; means "Run &lt;FONT face="Courier New"&gt;foo.exe&lt;/FONT&gt; and redirect its &lt;FONT face="Courier New"&gt;STDOUT&lt;/FONT&gt; to &lt;FONT face="Courier New"&gt;foo.txt&lt;/FONT&gt;, and redirect its &lt;FONT face="Courier New"&gt;STDERR&lt;/FONT&gt; to wherever &lt;FONT face="Courier New"&gt;STDOUT&lt;/FONT&gt; goes."&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;This is all well and good for redirecting to files, but there are also some built-in "devices" which act like files.&amp;nbsp; &lt;FONT face="Courier New"&gt;NUL&lt;/FONT&gt; is one such "device", which is used to just discard any output.&amp;nbsp; So running &lt;FONT face="Courier New"&gt;foo.exe &amp;gt;nul 2&amp;gt;&amp;amp;1&lt;/FONT&gt; would discard any and all output from &lt;FONT face="Courier New"&gt;foo.exe&lt;/FONT&gt;.&amp;nbsp; Since devices act like files, you'll notice you can't create files that are the same name as a device.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;For those of you who are keeping score at home, other output devices off the top of my head include:&lt;/FONT&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;FONT face=Verdana size=2&gt;&lt;FONT face="Courier New"&gt;LPT1, LPT2&lt;/FONT&gt;&lt;FONT face=Verdana&gt;,&amp;nbsp;etc.&amp;nbsp;&lt;/FONT&gt;(parallel ports, usually used for Line PrinTers)&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;FONT face=Verdana size=2&gt;&lt;FONT face="Courier New"&gt;COM1&lt;/FONT&gt;, &lt;FONT face="Courier New"&gt;COM2,&lt;FONT face=Verdana&gt; etc.,&lt;/FONT&gt; &lt;/FONT&gt;(serial ports)&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;FONT face=Verdana size=2&gt;&lt;FONT face="Courier New"&gt;AUX&lt;/FONT&gt; (auxilliary device - &lt;FONT face="Courier New"&gt;COM1&lt;/FONT&gt; by default)&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;FONT face=Verdana size=2&gt;&lt;FONT face="Courier New"&gt;CON&lt;/FONT&gt; (console - the default device, i.e., your screen)&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;FONT face=Verdana size=2&gt;&lt;FONT face="Courier New"&gt;PRN&lt;/FONT&gt; (printer - same as &lt;FONT face="Courier New"&gt;LPT1&lt;/FONT&gt;, though something in the back of my mind tells me there used to be a way to reassign this).&lt;/FONT&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&lt;FONT face=Verdana size=1&gt;&lt;STRONG&gt;Edit&lt;/STRONG&gt;: Reformatted for clarity.&lt;/FONT&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=427043" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/myocom/archive/tags/Batch/default.aspx">Batch</category></item><item><title>Opening web pages from the command line</title><link>http://blogs.msdn.com/myocom/archive/2005/06/07/426531.aspx</link><pubDate>Wed, 08 Jun 2005 02:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:426531</guid><dc:creator>myocom</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/myocom/comments/426531.aspx</comments><wfw:commentRss>http://blogs.msdn.com/myocom/commentrss.aspx?PostID=426531</wfw:commentRss><description>&lt;P&gt;&lt;FONT face=Verdana size=2&gt;I spend a lot of time in a CMD window.&amp;nbsp; I mean a &lt;STRONG&gt;lot&lt;/STRONG&gt; of time.&amp;nbsp; Often I'd like to open a web page, but opening up Internet Explorer and navigating my way to the page in question is such a chore.&amp;nbsp; I'm lazy.&amp;nbsp; I don't like mouse-clicks.&amp;nbsp; Enter the quicky batch file.&lt;/FONT&gt;&lt;/P&gt;
&lt;P dir=ltr&gt;&lt;FONT face=Verdana size=2&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;U&gt;traffic.cmd&lt;/U&gt; &lt;/FONT&gt;- This checks my local traffic conditions (thanks to the excellent folks at the WSDOT)&lt;BR&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @start &lt;/FONT&gt;&lt;A href="http://www.wsdot.wa.gov/Traffic/seattle/I405_53rd.htm"&gt;&lt;FONT face="Courier New"&gt;http://www.wsdot.wa.gov/Traffic/seattle/I405_53rd.htm&lt;/FONT&gt;&lt;/A&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P dir=ltr&gt;&lt;FONT face=Verdana size=2&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;U&gt;weather.cmd&lt;/U&gt;&lt;/FONT&gt; - This tells me the current conditions in my area&lt;BR&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @start &lt;/FONT&gt;&lt;A href="http://www.weather.com/outlook/recreation/golf/local/98052"&gt;&lt;FONT face="Courier New"&gt;http://www.weather.com/outlook/recreation/golf/local/98052&lt;/FONT&gt;&lt;/A&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;You get the idea...&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=1&gt;&lt;STRONG&gt;Edit&lt;/STRONG&gt;: Changed inadvertant italics&lt;/FONT&gt;&lt;FONT face=Verdana size=1&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=426531" width="1" height="1"&gt;</description></item><item><title>Backslashes vs. slashes - who knew?</title><link>http://blogs.msdn.com/myocom/archive/2005/06/07/426520.aspx</link><pubDate>Wed, 08 Jun 2005 01:45:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:426520</guid><dc:creator>myocom</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/myocom/comments/426520.aspx</comments><wfw:commentRss>http://blogs.msdn.com/myocom/commentrss.aspx?PostID=426520</wfw:commentRss><description>&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Here's something I'd never noticed until today, when I discovered it quite by accident.&amp;nbsp; In general, to run a program in a different directory, you specify the path with backslashes, such as &lt;FONT face="Courier New"&gt;C:\WINDOWS\system32\notepad.exe&lt;/FONT&gt;.&amp;nbsp; This should be no surprise.&amp;nbsp; What &lt;STRONG&gt;is&lt;/STRONG&gt; surprising, though, is that if you use call to run this, you can use forward slashes: &lt;FONT face="Courier New"&gt;call C:/WINDOWS/system32/notepad.exe&lt;/FONT&gt;.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;I'd love to know the reasoning behind this; it's not particularly useful unless you're a Linux guy who can't get out of the habit of using &lt;FONT face="Courier New"&gt;/&lt;/FONT&gt;.&amp;nbsp; Even then, though,&amp;nbsp;it's exceedingly unlikely that you'd precede everything with &lt;FONT face="Courier New"&gt;call&lt;/FONT&gt;.&lt;/FONT&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=426520" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/myocom/archive/tags/Batch/default.aspx">Batch</category></item><item><title>Bugs and assumptions</title><link>http://blogs.msdn.com/myocom/archive/2005/06/06/425974.aspx</link><pubDate>Tue, 07 Jun 2005 08:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:425974</guid><dc:creator>myocom</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/myocom/comments/425974.aspx</comments><wfw:commentRss>http://blogs.msdn.com/myocom/commentrss.aspx?PostID=425974</wfw:commentRss><description>&lt;P&gt;&lt;FONT face=Verdana size=2&gt;There's a fine line between an assumption and a bug.&amp;nbsp; If the assumptions are spelled out ahead of time, then it's not a bug if the script does what's expected,&amp;nbsp;taking the assumptions into consideration.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Having disclaimed that, then, here are some of the assumptions made for the &lt;FONT face="Courier New"&gt;makefiles.cmd&lt;/FONT&gt; and &lt;FONT face="Courier New"&gt;delallbut.cmd&lt;/FONT&gt; scripts:&lt;/FONT&gt;&lt;/P&gt;
&lt;P dir=ltr&gt;&lt;FONT face="Courier New" size=2&gt;&lt;U&gt;makefiles.cmd&lt;/U&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P dir=ltr&gt;&lt;FONT face=Verdana size=2&gt;1. This script assumes that the files that you'd like to create are either all in the same directory or that if you specify paths as arguments, that all directories you refer to already exist.&amp;nbsp; It will not create directories on the fly.&lt;/FONT&gt;&lt;/P&gt;
&lt;P dir=ltr&gt;&lt;FONT face=Verdana size=2&gt;For example, if you were to run &lt;FONT face="Courier New"&gt;makefiles.cmd foo bar baz&lt;/FONT&gt;&lt;/FONT&gt; &lt;FONT face=Verdana size=2&gt;you would end up with three files in the current directory: &lt;FONT face="Courier New"&gt;foo&lt;/FONT&gt;, &lt;FONT face="Courier New"&gt;bar&lt;/FONT&gt;, and &lt;FONT face="Courier New"&gt;baz&lt;/FONT&gt;.&amp;nbsp; If, however, you were to run &lt;FONT face="Courier New"&gt;makefiles.cmd dir1\foo dir2\bar dir3\subdir3\baz&lt;/FONT&gt;, you'd better make sure that &lt;FONT face="Courier New"&gt;dir1&lt;/FONT&gt;, &lt;FONT face="Courier New"&gt;dir2&lt;/FONT&gt;, and &lt;FONT face="Courier New"&gt;dir3\subdir3&lt;/FONT&gt; already exist or you'll get "&lt;FONT face="Courier New"&gt;The system cannot find the path specified&lt;/FONT&gt;" for each path that it can't get to.&lt;/FONT&gt;&lt;/P&gt;
&lt;P dir=ltr&gt;&lt;FONT face=Verdana size=2&gt;2. For files you specify on the command line, if there are already files of that name, they'll get clobbered.&amp;nbsp; This could easily be remedied by using &lt;FONT face="Courier New"&gt;&amp;gt;&amp;gt;&lt;/FONT&gt; rather than &lt;FONT face="Courier New"&gt;&amp;gt;&lt;/FONT&gt;.&amp;nbsp; The single &lt;FONT face="Courier New"&gt;&amp;gt;&lt;/FONT&gt; will spew the result of a command into a file specified.&amp;nbsp; The double &lt;FONT face="Courier New"&gt;&amp;gt;&amp;gt;&lt;/FONT&gt; will append to an existing file.&amp;nbsp; This is important to remember when you're writing scripts that create logfiles, for example.&amp;nbsp; I've been bitten by this before...&lt;/FONT&gt;&lt;/P&gt;
&lt;P dir=ltr&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;&lt;U&gt;delallbut.cmd&lt;/U&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&lt;A href="https://blogs.msdn.com/myocom/archive/2005/06/03/425062.aspx#425142"&gt;Anders&lt;/A&gt; is absolutely correct on both points:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;1. If you have a file that already has the read-only flag set, this script will not delete it.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Example: Create files &lt;FONT face="Courier New"&gt;foo&lt;/FONT&gt;, &lt;FONT face="Courier New"&gt;bar&lt;/FONT&gt;, &lt;FONT face="Courier New"&gt;baz&lt;/FONT&gt;, and &lt;FONT face="Courier New"&gt;gingerbreadman&lt;/FONT&gt; (&lt;FONT face="Courier New"&gt;makefiles.cmd&lt;/FONT&gt; is great for testing this, by the way).&amp;nbsp; Now make, say, &lt;FONT face="Courier New"&gt;gingerbreadman&lt;/FONT&gt;&lt;FONT face=Verdana&gt; read-only (&lt;FONT face="Courier New"&gt;attrib +r gingerbreadman&lt;/FONT&gt;).&amp;nbsp; When you run &lt;FONT face="Courier New"&gt;delallbut.cmd foo&lt;/FONT&gt;, you'll see that &lt;FONT face="Courier New"&gt;gingerbreadman&lt;/FONT&gt; still exists in that directory (can't &lt;FONT face="Courier New"&gt;del&lt;/FONT&gt; me, I'm the Gingerbread Man!).&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;2. If the file you choose not to delete already had the read-only flag set, this script will strip it off once it's done running.&amp;nbsp; If you depend on behavior #1 up there, you'll be unpleasantly surprised when you run this and find that your previously saved file suddenly disappears.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Example: Create files &lt;FONT face="Courier New"&gt;foo&lt;/FONT&gt;, &lt;FONT face="Courier New"&gt;bar&lt;/FONT&gt;, &lt;FONT face="Courier New"&gt;baz&lt;/FONT&gt;, and &lt;FONT face="Courier New"&gt;gingerbreadman&lt;/FONT&gt; again.&amp;nbsp; Set the +r flag on &lt;FONT face="Courier New"&gt;gingerbreadman&lt;/FONT&gt;.&amp;nbsp; Run &lt;FONT face="Courier New"&gt;delallbut.cmd gingerbreadman&lt;/FONT&gt;.&amp;nbsp; Now &lt;FONT face="Courier New"&gt;gingerbreadman&lt;/FONT&gt; still exists, but it no longer has the +r flag set.&amp;nbsp; Create file &lt;FONT face="Courier New"&gt;saveme&lt;/FONT&gt;.&amp;nbsp; Run &lt;FONT face="Courier New"&gt;delallbut.cmd saveme&lt;/FONT&gt;.&amp;nbsp; Uh-oh!&amp;nbsp; &lt;FONT face="Courier New"&gt;Gingerbreadman&lt;/FONT&gt; is gone!&amp;nbsp; &lt;A href="http://us.imdb.com/title/tt0126029/"&gt;Gumdrop buttons&lt;/A&gt; and all!&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;So, are these bugs?&amp;nbsp; Not anymore - I've spelled out the assumptions...&lt;/FONT&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=425974" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/myocom/archive/tags/Batch/default.aspx">Batch</category></item><item><title>So what the heck just happened there...?</title><link>http://blogs.msdn.com/myocom/archive/2005/06/03/so-what-the-heck-just-happened-there.aspx</link><pubDate>Sat, 04 Jun 2005 02:30:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:425049</guid><dc:creator>myocom</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/myocom/comments/425049.aspx</comments><wfw:commentRss>http://blogs.msdn.com/myocom/commentrss.aspx?PostID=425049</wfw:commentRss><description>&lt;P&gt;&lt;FONT face=Verdana size=2&gt;In the previous post, there was a fair amount of code and basically no explanation... Here's how it breaks down:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Naïve method:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set FILENAME=basename-%RANDOM%&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;CMD has a built-in variable called &lt;FONT face="Courier New"&gt;%RANDOM%&lt;/FONT&gt;. Simply put, it returns a random value between 0 and 32767. You can test this yourself by running &lt;FONT face="Courier New"&gt;echo %RANDOM%&lt;/FONT&gt; a few times at a prompt.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;This method, then, just creates an environment variable &lt;FONT face="Courier New"&gt;FILENAME&lt;/FONT&gt; as &lt;FONT face="Courier New"&gt;basename-2369&lt;/FONT&gt; or basename-7, or whatever the random number was. The problem is that if you run this enough times, eventually you'll get duplicate numbers. You also can't determine when that will be, exactly. You could get duplicates after two runs or it might take 32769 runs. So what we need is a...&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;__&lt;BR&gt;Better way:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for /f "delims=:. tokens=1-4" %%m in ("%TIME: =0%") do (&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set FILENAME=basename-%%m%%n%%o%%p&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; )&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Ok, so this gets a little more complex. First, let's look at the output of &lt;FONT face="Courier New"&gt;echo %TIME%&lt;/FONT&gt; (another built-in variable). Right now, I get &lt;FONT face="Courier New"&gt;16:21:52.73&lt;/FONT&gt; as the current time. So the fields from left to right are hours, minutes, seconds, hundredths of a second. Easy enough.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Now, the &lt;FONT face="Courier New"&gt;for&lt;/FONT&gt; loop there is where the magic comes in. Generally the &lt;FONT face="Courier New"&gt;/f&lt;/FONT&gt; switch on for means that you want to operate on a file: say, reading each line of a file and doing something interesting with it. However, the help for &lt;FONT face="Courier New"&gt;for&lt;/FONT&gt; says this:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&lt;FONT face="Courier New"&gt;You can also use the FOR /F parsing logic on &lt;EM&gt;an immediate string&lt;/EM&gt;, by making the filenameset between the parenthesis a quoted string, using single quote characters. It will be treated as a single line of input from a file and parsed. &lt;/FONT&gt;&lt;FONT face=Verdana&gt;(emphasis mine)&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;So this is what we're using here. The value of &lt;FONT face="Courier New"&gt;%TIME%&lt;/FONT&gt; is the string we're working on.&amp;nbsp; Note that the script also replaces spaces with zeros.&amp;nbsp; You'll get leading spaces if you run this from 1:00am -9:59am, so to preserve the sorting, we want leading zeros.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;The next bit of the &lt;FONT face="Courier New"&gt;for&lt;/FONT&gt; command is this: &lt;FONT face="Courier New"&gt;"delims=:. tokens=1-4"&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;This &lt;FONT face="Courier New"&gt;delims&lt;/FONT&gt; parameter indicates that we want to use : and . as our field delimiters (that is, split up the string everywhere there's a : or a .). The &lt;FONT face="Courier New"&gt;tokens&lt;/FONT&gt; parameter indicates which fields we're interested in. In this case, we're interested in all four: HH, MM, SS, and hh (for lack of a better abbreviation for hundredths). Then the &lt;FONT face="Courier New"&gt;%%m&lt;/FONT&gt; means we want to assign the first field to the variable &lt;FONT face="Courier New"&gt;%%m&lt;/FONT&gt;.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;The nifty (if occasionally annoying) thing about having multiple fields is that CMD automagically puts the rest of the fields we're interested in into subsequent variables. So HH goes into &lt;FONT face="Courier New"&gt;%%m&lt;/FONT&gt;, MM goes into &lt;FONT face="Courier New"&gt;%%n&lt;/FONT&gt;, etc.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Now, once we parse all that, we set &lt;FONT face="Courier New"&gt;FILENAME&lt;/FONT&gt; to basename-&lt;FONT face="Courier New"&gt;HHMMSShh&lt;/FONT&gt; and we're done.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;The problem with this is that if you run this loop a bunch of times around midnight, you'll get filenames like:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;basename-23500000&lt;BR&gt;basename-23590000&lt;BR&gt;basename-00010000&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;...and those don't sort properly: The file created after midnight will appear to come before the ones in the 11:00 hour. Again, you could solve this by using &lt;FONT face="Courier New"&gt;dir /od&lt;/FONT&gt;, but that's cheating.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;You might be asking at this point, "Why does this use &lt;FONT face="Courier New"&gt;for&lt;/FONT&gt; when it's not really a loop?" Excellent question. That's because &lt;FONT size=1&gt;*mumble mumble*&lt;/FONT&gt;. The real answer is "beats me". I suppose they (whoever "they" are) needed to stuff this functionality somewhere, and since &lt;FONT face="Courier New"&gt;for&lt;/FONT&gt; already had so many pathological cases, it was as good a place as any.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Ok, so on to the...&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;__&lt;BR&gt;Best way:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for /f "delims=/ tokens=1-3" %%a in ("%DATE:~4%") do (&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for /f "delims=:. tokens=1-4" %%m in ("%TIME: -0%") do (&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set FILENAME=basename-%%c-%%b-%%a-%%m%%n%%o%%p&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; )&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; )&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;This works much the same way as the "better" way, but it adds a couple of wrinkles. First, it parses the &lt;FONT face="Courier New"&gt;%DATE%&lt;/FONT&gt; variable (another built-in). For me, &lt;FONT face="Courier New"&gt;echo %DATE%&lt;/FONT&gt; returns &lt;FONT face="Courier New"&gt;Fri 06/03/2005&lt;/FONT&gt; at the moment. But it doesn't just parse &lt;FONT face="Courier New"&gt;%DATE%&lt;/FONT&gt;, there's some funny punctuation in there.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;The syntax for &lt;FONT face="Courier New"&gt;%DATE:~4%&lt;/FONT&gt; is hidden under &lt;FONT face="Courier New"&gt;set /?&lt;/FONT&gt;, oddly enough. What it means is "take the value of &lt;FONT face="Courier New"&gt;%DATE%&lt;/FONT&gt; and strip off the first four characters - the day of the week and the space. So, in my case, that means that &lt;FONT face="Courier New"&gt;%DATE:~4%&lt;/FONT&gt; results in &lt;FONT face="Courier New"&gt;06/03/2005&lt;/FONT&gt;. The outer for loop uses / as its field delimiters, so we end up with the fields DD MM YYYY in &lt;FONT face="Courier New"&gt;%%a&lt;/FONT&gt;, &lt;FONT face="Courier New"&gt;%%b&lt;/FONT&gt;, and &lt;FONT face="Courier New"&gt;%%c&lt;/FONT&gt;.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;The next &lt;FONT face="Courier New"&gt;for&lt;/FONT&gt; loop is exactly the same as the one in the "better" method. It stuffs HH MM SS hh into &lt;FONT face="Courier New"&gt;%%m&lt;/FONT&gt;, &lt;FONT face="Courier New"&gt;%%n&lt;/FONT&gt;, &lt;FONT face="Courier New"&gt;%%o&lt;/FONT&gt;, &lt;FONT face="Courier New"&gt;%%p&lt;/FONT&gt;.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Finally, we assign &lt;FONT face="Courier New"&gt;FILENAME&lt;/FONT&gt; the value of &lt;FONT face="Courier New"&gt;basename-%%c-%%b-%%a-%%m%%n%%o%%p&lt;/FONT&gt;, or for my example, &lt;FONT face="Courier New"&gt;basename-2005-06-03-16215273&lt;/FONT&gt;.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;If you run this a bunch of times, you'll get filenames that sort correctly all of the time.&lt;BR&gt;&lt;/FONT&gt;&lt;FONT face=Verdana size=2&gt;__&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&lt;STRONG&gt;Edit&lt;/STRONG&gt;: Added leading zeros to the times, where necessary, to preserve sorting.&lt;/P&gt;&lt;/FONT&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=425049" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/myocom/archive/tags/Batch/default.aspx">Batch</category></item><item><title>Creating unique filenames in a batch file</title><link>http://blogs.msdn.com/myocom/archive/2005/06/03/creating-unique-filenames-in-a-batch-file.aspx</link><pubDate>Sat, 04 Jun 2005 02:15:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:425046</guid><dc:creator>myocom</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/myocom/comments/425046.aspx</comments><wfw:commentRss>http://blogs.msdn.com/myocom/commentrss.aspx?PostID=425046</wfw:commentRss><description>&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Someone today was asking how to create unique filenames. They had some process which ran in a loop, and they wanted to direct the output of that process to a file, but rather than always overwriting the same file, they wanted to keep history using distinctive filenames.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;There are a few ways to do this:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Naïve way:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set FILENAME=basename-%RANDOM%&lt;/FONT&gt;&lt;/P&gt;
&lt;P dir=ltr style="MARGIN-RIGHT: 0px"&gt;&lt;FONT face=Verdana size=2&gt;Later, sort by using&amp;nbsp;&lt;FONT face="Courier New"&gt;dir /od basename*&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;The problem is that these files have the possibility of being non-unique, since &lt;FONT face="Courier New"&gt;%RANDOM%&lt;/FONT&gt; only generates numbers between 0 and 32767. For a small number of files, you probably won't get a collision, though, and this is less code than the "better" way below...&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;__&lt;BR&gt;Better way:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for /f "delims=:. tokens=1-4" %%t in ("%TIME: =0%") do (&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set FILENAME=basename-%%t%%u%%v%%w&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; )&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;This gives you precision down to .01 seconds, which may be overkill, depending on how tight your loop is. It does have one bug as far as sorting goes (unless you use &lt;FONT face="Courier New"&gt;dir /od&lt;/FONT&gt; again, but that's cheating…); if you run this over midnight, your sorting will be off (00:00:01 will sort before 23:59:59). If you don't plan on running it overnight, then this should work fine. But for a truly robust system, use...&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;__&lt;BR&gt;Best way:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for /f "delims=/ tokens=1-3" %%a in ("%DATE:~4%") do (&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for /f "delims=:. tokens=1-4" %%m in ("%TIME: =0%") do (&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set FILENAME=basename-%%c-%%b-%%a-%%m%%n%%o%%p&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; )&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; )&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;This gives you the same precision (.01 seconds) as the previous way, but sorts nicely since the date (YYYY-MM-DD) comes first in the filename.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;__&lt;BR&gt;Caveat to all of these methods: These scripts are not locale-agnostic. If you change your date/time formats, these may need to be tweaked.&lt;BR&gt;__&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana&gt;&lt;STRONG&gt;Edit&lt;/STRONG&gt;: Fixed the reference to %TIME% so that the script works in the morning too.&amp;nbsp; Time in Windows includes a leading space for single-digit hours.&amp;nbsp; While spaces aren't technically&amp;nbsp;a problem - they're perfectly legal in filenames - they're sort of&amp;nbsp;a pain...&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana&gt;__&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana&gt;&lt;STRONG&gt;Edit #2&lt;/STRONG&gt;: Several people correctly pointed out that removing the leading space also messes up the sorting.&amp;nbsp; The scripts now use a leading zero.&amp;nbsp; Thanks, all!&lt;/FONT&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=425046" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/myocom/archive/tags/Batch/default.aspx">Batch</category></item><item><title>Two quick file-manipulation scripts from the vault</title><link>http://blogs.msdn.com/myocom/archive/2005/06/03/425062.aspx</link><pubDate>Sat, 04 Jun 2005 02:15:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:425062</guid><dc:creator>myocom</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/myocom/comments/425062.aspx</comments><wfw:commentRss>http://blogs.msdn.com/myocom/commentrss.aspx?PostID=425062</wfw:commentRss><description>&lt;P&gt;&lt;FONT face=Verdana size=2&gt;There are a couple of scripts that have been with me since the beginning of time. I don't use them that much anymore, but they occasionally come in handy. I'm always pleasantly surprised to find that I still have them when I need them. One makes files and the other deletes files.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;The first is called 'makefiles.cmd'. It just creates any files that you specify on the command line. This is handy for making some little scratch files you might need to test another script.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;U&gt;makefiles.cmd&lt;/U&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @for %%x in (%*) do @echo %%x &amp;gt; %%x&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;This line loops over every argument passed in on the command line, say I run this as: &lt;FONT face="Courier New"&gt;makefiles foo.txt bar.txt donotdelete.txt&lt;/FONT&gt;. This line, then uses &lt;FONT face="Courier New"&gt;foo.txt&lt;/FONT&gt; as the first argument, &lt;FONT face="Courier New"&gt;bar.txt&lt;/FONT&gt; as the second, etc. It then echos the name of that file and redirects that into a file of that same name. That is, 'foo.txt' will just have the text 'foo.txt' in it.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&lt;BR&gt;The second is called 'delallbut.cmd'. This deletes all files in the current directory except for the one you specify on the command line.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;U&gt;delallbut.cmd&lt;/U&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @echo off&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if defined ECHO (echo %ECHO%)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for %%x in (%*) do attrib +r %%x &amp;gt;nul 2&amp;gt;&amp;amp;1&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; del /q . &amp;gt;nul 2&amp;gt;&amp;amp;1&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for %%x in (%*) do attrib -r %%x &amp;gt;nul 2&amp;gt;&amp;amp;1&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;This deserves a little bit of explanation. I often start scripts with those first two lines. If I want to see what a given script is doing (usually when I'm testing it or something unexpected is happening when I run it), I set an environment variable, &lt;FONT face="Courier New"&gt;ECHO&lt;/FONT&gt;, to on: &lt;FONT face="Courier New"&gt;set ECHO=on&lt;/FONT&gt;. So the first line here turns echo off (the default), then checks to see if I have &lt;FONT face="Courier New"&gt;ECHO&lt;/FONT&gt; set to on, and if so, turns it echo on. Note that I can also turn echo back off by setting &lt;FONT face="Courier New"&gt;ECHO&lt;/FONT&gt; to off. There's either a bug or an undocumented feature here, wherein if I set &lt;FONT face="Courier New"&gt;ECHO&lt;/FONT&gt; to, say, "Hi, how are you?", that text will be echoed at the beginning of this script. Sure, I could explicitly check to see whether &lt;FONT face="Courier New"&gt;ECHO&lt;/FONT&gt; is set to on or off, but that's more work than it's worth, in my opinion.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;The next three lines are the meat of the script. The first line loops over all of the files you've passed in (like we did in &lt;FONT face="Courier New"&gt;makefiles.cmd&lt;/FONT&gt;). The action it takes for each of these files is to set the Read-only file attribute. The &lt;FONT face="Courier New"&gt;&amp;gt;nul 2&amp;gt;&amp;amp;1&lt;/FONT&gt; bit basically says "throw away the output of &lt;FONT face="Courier New"&gt;attrib&lt;/FONT&gt; (if any)". I'll go into more detail about that little bit in a later posting.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;So now every file we want to save is marked read-only. The next line is a shortcut for &lt;FONT face="Courier New"&gt;del *.*&lt;/FONT&gt;, or 'delete all files in this directory'. And again, we throw away any text that &lt;FONT face="Courier New"&gt;del&lt;/FONT&gt; might output. The following line turns the read-only flag back off, and we're done. All the files in this directory have been blown away except the ones we've specified. If you used the example for &lt;FONT face="Courier New"&gt;makefiles.cmd&lt;/FONT&gt;, then run &lt;FONT face="Courier New"&gt;delallbut foo.txt donotdelete.txt&lt;/FONT&gt;, you'll notice that &lt;FONT face="Courier New"&gt;bar.txt&lt;/FONT&gt; has disappeared, but &lt;FONT face="Courier New"&gt;foo.txt&lt;/FONT&gt; and &lt;FONT face="Courier New"&gt;donotdelete.txt&lt;/FONT&gt; are still intact.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Now, for bonus points, what problems can you find in these scripts? There are some assumptions made in each of these scripts. Leave your answers in the comments. &lt;/FONT&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=425062" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/myocom/archive/tags/Batch/default.aspx">Batch</category></item><item><title>Typos vs. muscle memory</title><link>http://blogs.msdn.com/myocom/archive/2005/06/03/425059.aspx</link><pubDate>Sat, 04 Jun 2005 02:05:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:425059</guid><dc:creator>myocom</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/myocom/comments/425059.aspx</comments><wfw:commentRss>http://blogs.msdn.com/myocom/commentrss.aspx?PostID=425059</wfw:commentRss><description>&lt;P&gt;&lt;FONT face=Verdana size=2&gt;It occurs to me that my mistypings of 'notepad' and 'exit' are probably more the result of muscle-memory since I type those so often. The mistakes I make are due to one hand hitting its letter before the other (correct) hand hitting its.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Just a thought.&lt;/FONT&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=425059" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/myocom/archive/tags/Deep+Thoughts/default.aspx">Deep Thoughts</category></item></channel></rss>