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
:~0,-10%
In general, to cut a string from a variable, you should use one of the following constructions:
%var:~n,m%
%var:~n,-m%
%var:~n%

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!

Translate