Wednesday, December 23, 2009

Buy Dr.Batcher with 40% discount on December 27

Mental Works Computing Software and Bits du Jour offer you special 40% discount for Dr.Batcher on December 27, 2009. Only that day you will be able to buy Dr.Batcher only for $17.97 and receive all benefits of the registered version of Dr.Batcher including:
* Unlimited time of use without nag-screens and other reminders
* All functions of the registered version
* Top-priority support
* Free minor updates (i.e. from version 2.0 to versions 2.1, 2.2, etc.)
* Money back guarantee within 30 days of the product purchase
Tell your friends and co-workers about this offer! Save your time and your money with the help of Dr.Batcher!
Details here:

Sunday, December 13, 2009

Creating Directories in Batch Files

Creating new directories using batch files is a common task for system administrators and even home users. But it's not so simple to create a directory with the proper name sometimes. For example, let's consider that we want to create a directory named using the current date and current time. How will you create it through a batch script? Probably you will type something like this:
md %date%%time:~0,2%%time:~3,2%
Now let's execute this code... What a surprise! We get two different folders instead of a single one. Why? Windows includes space into the
folder's name, and thus 'md' command considers creating two directories. Two folders will be created when time is then 10 a.m., e.g. when it can be represented with a single digit.
To solve this problem, we decided to remove space between the date and time. Here is the proper code to create directory with such name:
set d=%date%_%time:~0,2%.%time:~3,2%
set dt=%d: =%
md %dt%
This code will always create a single folder any time you call it.

Monday, December 7, 2009

Dr.Batcher 2.0.1 Is Released

We're glad to introduce Dr.Batcher 2.0.1, a new version of our award-winning batch files creation utility. Though this is just a minor update, it brings some really useful features and improvements for every user of Dr.Batcher. Here are some of them:
  • Support for nested compound commands
  • Support for extended 'IF' syntax
  • Arabic translation
  • Batch scripts parser improved
  • Lots of small bugfixes.
You can download a new version here. Hope you'll enjoy it.

Thursday, December 3, 2009

Comments in Batch Scripts

Do you know how to comment a line in a batch script? Sure most of you know that it is possible with 'REM' at the start of certain line. But there are still some alternative ways. These ways are really popular among batch files creators but they can produce some unexpected errors while the execution of a batch file.
The most popular commenting style for batch scripts looks like this:
:: This is a comment
And the other one looks even simpler:
: This can also be a comment
You know that batch files syntax says that names of labels start with ":" character. So the comments above are labels for the batch files interpreter. And this is the source for some specific errors. For example, if you add such comment into blocks of code inside IF or FOR statements (between brackets), you'll see the error message. So you need to write comments before the beginning of such code block, or use traditional 'REM' instead of colons.

Monday, November 23, 2009

'Else' in Batch Files Conditions

The following version of Dr.Batcher, which is going to be released in a few days, will bring support for extended syntax of 'If' command. So we decided to give you some additional information on using 'Else' in batch file conditions.
The command after 'Else' keyword will be executed if the condition appears to be false. You should know that the whole 'If' statement must be written in the same line, so you cannot write your batch file in the following manner:
If errorlevel 1 Echo Error!
Else Echo Everything's OK!

But the following code will work perfectly:
If errorlevel 1 (
Echo Error!

) Else (
Echo Everything's OK!

Note that you can add extra commands between brackets and thus compose quite complex scripts.

Saturday, November 14, 2009

Cutting Characters in Batch Scripts

It's necessary sometimes to cut some characters from the value of a variable in a batch script. For example, you need to rename a file having a too long name, or need to pass a certain string as a parameter for another batch file and need to cut last 5 characters. How can you cut these characters from a string? There is really simple solution provided by the command interpreter. For example, if you want to cut last ten characters from the first parameter given to your batch file, use the following code:
SET param1=%1%
SET param2=%param1
In general, to cut a string from a variable, you should use one of the following constructions:

The first line cuts m characters from the string assigned to variable var, starting with n-th character (beginning from zero). The second line removes m characters from the string's tale. The third one cuts all characters in the string beginning with n-th character.

Tuesday, November 10, 2009

Batch Scripts and Windows Registry

One of the most common tasks you can meet during the batch scripts usage is modification of the Windows registry. It is likely that Microsoft still respects users of batch files because it provides them with several powerful tools allowing to add, delete or change registry keys and their values.
The most useful command is called reg. As it is stated in official manual, this command 'adds, changes, and displays registry subkey information and values in registry entries'.
There is no use in repeating words written by Microsoft, so I should just mention the alternative way to add keys or values to the registry. You can create REG file using your batch script and then call RegEdit to add keys described in this REG file to the registry. Of course, this way may look quite exotically, but it's really useful in some cases.

Thursday, November 5, 2009

Dr.Batcher 2.0 Is Finally Out!

I'm glad to introduce Dr.Batcher 2.0. This version of this batch files editor is designed to make them handier for all kinds of users. I won't speak much about it, just show you the list of features of the new version. New features are highlighted with bold text.
  • Simple mode: create BAT files with visual editors and wizards
  • Professional mode: create BAT files with full-featured and highly customizable text editor with syntax highlighting, code tooltips, lines numbering and bookmarks
  • Easy switching between different modes of batch file editor
  • Built-in support for most commonly used standard Windows and DOS commands
  • Support for easy search of additional information on commands in the Web via Google, Yahoo, MSN Search
  • Support for looking through environment variables and copying their values
  • Expandability: easy to add new commands through XML files with their descriptions
  • Support for BAT scripts in Windows and DOS encoding, fast conversion of text from one encoding to another
  • Support for automatic updates
  • Exporting BAT files to HTML, RTF (Microsoft Word), TeX and printing them with syntax highlight
  • Support for changing language of Dr.Batcher's user interface
  • Windows 7 support
  • Templates and examples
Some notes on commands and examples. In this version Dr.Batcher supports about 140 standard commands. This number is much greater than number of commands in versions 1.x (about 70 commands). Amount of the provided examples has also grown. Hope you'll find really useful ones among them.
Of course, still there is a lot of work on Dr.Batcher to be done. Subscribe the RSS Feed on Dr.Batcher's Web site to follow our news!

Wednesday, October 28, 2009

Errorlevel: Checking for Errors while Executing a Batch Script

Sometimes it's necessary to check for errors while executing a batch script. Command interpreter has built-in support for storing the return code of the command or program most recently executed. Note: error level is not a variable from the point of a batch script writer. You can't check it with the following code:
If %Errorlevel%==1 goto Error
You should write instead this line:
If Errorlevel 1 goto Error
You can't check whether error level equals to zero or other defined value. "If errorlevel" executes the command following this statement if error level is equal or greater than the specified value. This strange syntax is very handy because usually you don't have to check the error level for any value except zero. So using this construction you avoid checking for a large amount of different values.
Though you can use alternative syntax that also works:
If %Errorlevel% NEQ 0 goto Error
Here you can see that error level is used like a variable. But it's a fake variable. You can't use it in any other way except the way shown above. Note: this code works only under Windows NT family operating systems (NT 4.0, 2000, XP, etc.). So if you need to write MS-DOS-compatible batch file, you have to use "If errorlevel" command.

Tuesday, October 20, 2009

Pauses and Delays in Batch Scripts

In some cases you need to wait for a certain time after calling an application from your batch file. For example, it's useful when this application must finish its work. How can one include delay in his batch script? There are several different solutions.
  1. The first way is the simplest one. You can just include "pause" command in your script. This way has a really big drawback: this command requires a key pressing to continue the execution. So this command cannot be used in pure automated scripts, because you must ask someone to press a key.
  2. The second way is to use ping command. Of course, this command is not designed for adding delays to the batch files, but it's really handy to use it in this case. The following code will make delay for ten seconds: ping -n 11 -w 1000 > nul
  3. You can use 'Sleep' utility from Windows Resource Kit. Its usage will look like sleep 10.
I'd better use the second variant because it's quite simple and will run on all versions of Windows without any external tools.

Friday, October 16, 2009

Checking for Existence of Variables and Parameters

Sometimes it's necessary to check in a batch file whether a certain variable is assigned. For example, it's useful when you need to check for some condition in "procedure" under certain label from main batch script. The usual way to check for existence looks like this:
if defined %VARIABLE% echo Variable exists!
But if you try to perform the same trick with parameters given to your batch script while its execution, you will be surprised. Code like
if defined %3 echo Parameter defined!
will not work correctly.
So what should one do to check whether certain parameter is passed to the batch file? The perfect solution is to compare the value of this parameter to empty string:
if "%1"=="" echo Help on parameters...
It's necessary to perform such check for existence of certain parameters if they are expected by your batch file. You should show short summary about the parameters of your batch file if there are less parameters than you expected. This simple technique will make your script more friendly. Even if one day you forget what parameters you need pass to it, you wouldn't read its code once more to remember them.

Monday, October 12, 2009

Working on Dr.Batcher 2.0 Beta

The first post on this blog is going to be about working on the next release of Dr.Batcher. Ok, it's a good topic.
The most interesting and valuable feature of Dr.Batcher 2.0 must be Simple mode of the script editor. What does this mean? Imagine that you speak to computer in English while writing a batch script. So you write "Delete file" instead of "Del", "Register library" instead of "regsvr32.exe", etc. You have no need to remember all the keys of each command, because the editor con tell you everything you need to know on each parameter.
This will look somehow like this:
It's not hard to develop such tool for the new batch scripts creation. But if you develop pure editor that allows you to edit the existing batch files, you should create a batch script parser. The parser is the most difficult component of Dr.Batcher to develop, and the major part of current beta-testing work is being performed to make the parser work right with any kind of batch files. But it's needful because users want to edit their old scripts and update them. We believe that our work on parser won't be a waste of time.