March 21
Progressive Dots
I just found out about this (thanks to Live Search!) from a fellow Canadian's blog entry "batch file snippets" and it's got me super excited.
Haven't you ever found it annoying that you can't print to a line without a newline (carriage return/line feed) in a batch script? (At least, I didn't know how to.) Well, now you can!
For instance:
echo Copying files .
for %%f in (A B C D) do (
echo .
xcopy %%f %DEST% /cqy 2>&1>NUL
)
would give you:
Copying files .
.
.
.
.
as opposed to a progressive:
Copying files ....
So what you actually want is:
set /p CRLF=Copying files .<NUL
for %%f in (A B C D) do (
set /p CRLF=.<NUL
xcopy %%f %DEST% /cqy 2>&1>NUL
)
Don't tell me that's not cool! How does it work? The '/p' option given to set is asking for user input:
SET /P variable=[promptString]
The /P switch allows you to set the value of a variable to a line of input entered by the user. Displays the specified promptString before reading the line of input. The promptString can be empty.
The key is that it prompts for input *on the same line*! And by redirecting the NUL device into it, you get an immediate return. How absolutely clever.
I love it!