Gonzo TechNet
DOS (Batch File Programming)

Yes, even in this day and age, there are still times when I need to write a "batch file". (It just sickens me...) To make it worse, MicroSlut, in its infinite wisdom, has yet to release a decent "shell". Rather than UPDATE DOS by adding new features, it continues to release NEW scripting languages. There has been VBScript,WHS, and now "PowerShell". Yet, even with all the bells, whistles, and object oriented razzmatazz, you still can't write a simple script to parse some strings and pass parameters to functions without spending a month learning a new language. Can't MicroSlut just implement a GNU version of Bash/Borne/CSH as part of its base distribution? Nope, then it wouldn't be a proprietary package that they could control into oblivion and obscurity.

So, I (we) are stuck having to do things the "old way".

How to process a string list

This was a bit tricky. I had to search high and low to find the answer, but, finally found an example using the DOS FOR IN syntax.

@echo off cls set mylist=item1 item2 item3 item4 item5 item6 item7 echo * mylist :%mylist% echo * testing FOR %%a IN (%mylist%) DO ( echo [%%a] )
How to get the current drive letter from a batch file

Giving credit where credit is due...  Wiki Batch Files:Current_Drive Letter

Using %CD% and DOS string modifiers we can do a lot of things. Open cmd.exe and type "echo %CD%". It will show like "C:\Documents and Settings\some user" Type:
echo %CD:~0,1%
Then it will show "C". So instead of entering set curdisk=h in a batch file, we can use set curdisk=%CD:~0,1%
So, to set and display the current drive, create a batch file with the following:
@echo off set curdisk=%CD:~0,1% echo * echo * Current drive is [%curdisk%] echo *
How to print a blank line with ECHO in a batch file
To print a blank line from a batch file, call "echo" with a single '.' IMMEDIATELY after the 'echo'.
How to test for a blank/empty string in a DOS parameter

Since there is no test for empty/blank/null in DOS, you have to work around the "emptiness". The way to do this is to take the paramater, wrap it in parenthesis "()",and then test to see if the parameter equals the pair of parenthesis. Crude and simple, but it works. The text below is part of a file called "isempty.cmd". It expects that the first parameter is a string. If it the parameter/string is empty, it will tell you so.

@echo off rem rem Check to see if the first parameter is empty or not rem echo. if (%1)==() ( echo * It's empty! )else ( echo * Parameter 1 contains the string [%1] )

Once you have saved it to a file, open a DOS/CMD window and excute with and without a something as the paramater

D:\junk> isempty NOPE! * Parameter 1 contains the string [NOPE!] D:\junk> isempty It's empty! D:\junk>
Home | TechNet | ADO.Net | DOS | ASP.NET | IIS | VB.NET | VIM (vi) | Windows | XHtml
MS-SQL | T-SQL | SSIS | Oracle