Rob van der Woude's Scripting Pages

News Archives 2022 Q1


[ Back to the current news page... ]


• I added information on IF ... ELSE IF ... ELSE ... constructions in batch files.


CompareFiles.exe is a new tool to compare two files.
First it compares file sizes, when these don't match the files are different and the program aborts.
If the file sizes match, the timestamps are compared; if these don't match, and the /IT switch (Ignore Timestamps) is not used, the program wiil abort.
If the timestamps do match, or the /IT switch is used, the program compares the MD5 checksums of the files.
The results are shown on screen and returned as "errorlevels", see the programs on-screen help for details.
An example of how to use it:
CompareFiles.exe file1 file2
IF NOT ERRORLEVEL 0 ECHO An error occurred
IF     ERRORLEVEL 1 ECHO Files are different
CompareFiles.exe file1 file2
IF %ErrorLevel% LSS 0 ECHO An error occurred
IF %ErrorLevel% GTR 0 ECHO Files are different
IF %ErrorLevel% EQU 0 ECHO Files are identical


DefaultQuickEditMode.bat is a new batch file to get or set the default Quick-Edit mode for all consoles (may affect PowerShell consoles too).
QuickEditMode.exe has also been updated, it can now also change the default Quick-Edit mode for all consoles using the optional /D switch.


• OK, one final (?) update for Mause.exe: like the previous version it will disable the console's Quick-Edit mode, but the new version will restore the original Ouick-Edit state on exit.


QuickEditMode.exe is a new program to get or set the current console's Quick-Edit mode.
I wrote it to assist in testing Mause.exe's intermittent problems with Quick-Edit mode.
QuickEditMode.exe does not display anything on screen, except its help text.
When run without arguments ("get mode"), QuickEditMode.exe's return code will tell you if Quick-Edit mode is on (1) or off (0).
With command line argument ("set mode"), you can either enable (1) or disable (0) Quick-Edit mode, and a return code 0 indicates success, -1 indicates failure.
An example of how to use it:
:: Detect initial Quick-Edit state
SET InitialQuickEditMode=%ErrorLevel%
:: Disable Quick-Edit mode for now
QuickEditMode.exe 0
(do your thing)
:: Restore initial Quick-Edit state
QuickEditMode.exe %InitialQuickEditMode%
• Speaking of Mause.exe, while working on QuickEditMode.exe I found and fixed the probable cause of Mause's problems: the logical operators I used were mixed up (swapped And and Or, ooooops).


Mause.exe has been updated again, still trying to prevent mouse clicks from selecting text if the console is in Quick-Edit mode (hard to reproduce, so a challenge to test).


Mause.exe has been updated, trying to prevent mouse clicks from selecting text in the console, which would halt all output until the Esc key is pressed.


• I added a new page on validating variables in batch files, i.e. how to verify that a string matches a specific format, like hexadecimal, IPv6 address, IMEI number, etc.


DecToBin.bat is a new batch file using only CMD.EXE's internal commands to convert a decimal number to 31-bit binary.
It was derived from DecToOct.bat, though without the check afterwards.
BinToDec.bat is a new batch file using only CMD.EXE's internal commands to convert a 31-bit binary number to decimal.
It is a simplified, completely rewritten version of Bin2Dec.bat.
By the way, don't expect me to publish HexToDec.bat or OctToDec.bat, these you can easily implement yourself (hexadecimal to decimal: SET /A 0x0%~1 and octal to decimal: SET /A 0%~1).


• A bug in ToString.exe is fixed: it would trip when parsing time strings with a comma for decimal separator, even if that is the standard for the current culture.
The work-around was to add code that replaces any decimal separators with dots and tries parsing again.
So now ToString.exe "{0:yyyyMMddTHHmmssfffzzz}" %Time% will return 20220517T070953000+02:00 even on Dutch computers.
• Next update of ToString.exe: it now also accepts redirected input for its arguments (template is still required on the command line), and will even work on multiple lines of redirected input.


Formating numbers in batch files is so complicated, whereas in .NET it is so easy.
That's why I wrote ToString.exe, a batch tool to format numbers and dates the .NET way.


DecToHex.bat and DecToOct.bat have been updated: after displaying the results, the batch files perform a final check to see if those results are correct, and display a warning if not.
• I added a new page on formating numbers in batch files.


Dec2Hex.bat, a batch file using PING for decimal to hexadecimal conversion, has been rewritten.
Its code is much simpler, and it now accepts any type of integer, as well as calculations on the command line, e.g. Dec2Hex.bat 80 * 0x0200
The downside is that the input range is cut in half, from 0xFFFFFFFE down to 0x7FFFFFFF.
• Guess what: DecToHex.bat could also be tremendously simplified, still using CMD.EXE's internal commands only.
Since it now also accepts any type of integer, as well as calculations on the command line, and the input ranges of both batch files are equal, I'd say it beats Dec2Hex.bat.
• From DecToHex.bat to DecToOct.bat (Decimal to Octal) required minimal modifications: divide by 8 instead of 16, and shift 3 bits instead of 4.


• I dedicated a separate page to the explanation of the text alignment technique used for ListVerbs.bat.


ListVerbs.bat is the batch equivalent of ListVerbs.exe, but always in Verbose mode.
For example, the command ListVerbs.bat .odt might return something like this:
Extension = .odt
File Type = Word.OpenDocumentText.12
        Edit                  "C:\Program Files\Microsoft Office\Root\Office16\WINWORD.EXE" /vu "%1"
        New                   "C:\Program Files\Microsoft Office\Root\Office16\WINWORD.EXE" /n /f "%1"
        OnenotePrintto        "C:\Program Files\Microsoft Office\Root\Office16\WINWORD.EXE" /j "%1" "%2"
        Open                  "C:\Program Files\Microsoft Office\Root\Office16\WINWORD.EXE" /n "%1"
        OpenAsReadOnly        "C:\Program Files\Microsoft Office\Root\Office16\WINWORD.EXE" /h /n "%1"
        Print                 "C:\Program Files\Microsoft Office\Root\Office16\WINWORD.EXE" /i "%1"
        printto               "C:\Program Files\Microsoft Office\Root\Office16\WINWORD.EXE" /j "%1" "%2"
        ViewProtected         "C:\Program Files\Microsoft Office\Root\Office16\WINWORD.EXE" /vp "%1"
Note: I know this looks different from my earlier example with the C# version, but that's because I just installed Microsoft Office 2021 which "hijacked" the .odt file type.
Try it, the output of both programs will look almost identical.
It will not come as a surprise, however, that the executable is much faster.
• While working on ListVerbs.bat, ListVerbs.exe had a minor update: in Verbose mode, its output text is now properly aligned in columns.


CheckVarsVBS.exe has been updated: Thanks Joe


• I admit I never suspected to ever need it, but I did: I had to add floppy disk drives to the detected hardware in Hardware.hta.


Drives.exe has been updated: the new version will return more details for local floppy and harddisk drives when the /T switch is used.


ListVerbs.exe is a new program to find the shell verbs for a specified file type.
To find verbs for use in PowerShell or C# you can use normal mode, which will list the verb names only.
For use with batch files, use verbose mode (/V switch) to get the command lines for the available verbs.
For example, the command ListVerbs.exe .odt /V might return something like this:
Extension = .odt
File Type = LibreOffice.WriterDocument.1 (OpenDocument Text)
	new		"C:\Program Files\LibreOffice\program\soffice.exe" -n "%1"
	open		"C:\Program Files\LibreOffice\program\soffice.exe" -o "%1"
	print		"C:\Program Files\LibreOffice\program\soffice.exe" -p "%1"
	printto		"C:\Program Files\LibreOffice\program\soffice.exe" -pt "%2" "%1"


Easter.exe is a new program to calculate the date of Easter Sunday for the specified year.
It is the C# version of my earlier PowerShell Easter code snippet.
A trimmed version has been added to my C# Code Snippets page as well.


• After many experiments I finally managed to create a PowerShell script to use OpenOffice to convert a text document to PDF.
Compared to Microsoft Office automation, OpenOffice automation is a real nightmare...


• And the most recent addition to the *2Txt series is Epub2Txt.exe, a new program to extract plain text from EPUB files and send it to the console.


WPD2Txt.exe is a first attempt at extracting plain text from a WordPerfect file.
It is far from perfect, the extracted text contains lots of "garbage" and most accented characters are lost.
I modified the information I found on the WordPerfect file format by Dan Tobias, to correct for spaces, linefeeds and é, but more modifications will be required for accented characters.

Thanks Dan and coeditors
WPD2Txt.exe's functionality has also been integrated in Word2Txt.exe.
With Word installed, WordPerfect files will be converted way better than without Word.


Rtf2Txt.exe is a new program to extract the unformated text from a Rich Text Format (.RTF) file.
It uses a hidden Windows Forms RichTextBox to convert RTF to plain text (tip by Wendy Zang)
The code has also been added to my C# Code Snippets and PowerShell Code Snippets pages.

Thanks Wendy
Word2Txt.exe has been updated with Rtf2Txt.exe's functionality.
So now it can handle any file format recognized by Word if Word is installed, otherwise it can still handle .DOC, .DOCX, .ODT and .RTF files.
ODT2Txt.exe is a new program to read the plain text from an OpenOffice .ODT file without requiring OpenOffice.
Its code has been used in Word2Txt.exe too.


• Both Word2Txt.exe and Docx2Txt.exe have been updated:


Word2Txt.exe is a new program, combining a stripped down version of Word2Any.exe, and Doc2Txt.exe and Docx2Txt.exe.
If Word is available, the program will use Word to extract plain text from the specified document (which may have any format recognized by Word), if Word isn't available it will use one of the alternative approaches for .DOC and .DOCX files only.


Doc2Txt.exe is a new program to extract the unformated text from a .DOC Word file, without requiring Word.
From the outside, it looks similar to Docx2Txt.exe, but the different Word file formats .DOC and .DOCX require completely different approaches.
Docx2Txt reads a .DOCX file as a ZIP file containing the text file, whereas Doc2Txt treats .DOC files more or less as "garbled text", using regular expressions to extract only the required plain text.


• I added a PowerShell snippet I'm rather proud of: Calculate Easter date for any year in 6 lines of code (plus several more for comments, parameter handling and presentation of results; most relevant lines are 3, 4, 11, 13, 15 and 17).
I have seen many pieces of code, including my own Easter.bat, that most people, including myself, will never understand, but I hope this PowerShell code does make some sense 


Docx2Txt.exe is a new program to extract the unformated text from a .DOCX Word file, without requiring Word.
It treats the Word file as a ZIP file (this works with .DOCX format but not with .DOC), reads the content of Word\document.xml, and removes the XML tags.


Word2OpenOffice.exe is a simple console program to convert Word documents (.doc and .docx only) to OpenOffice (.odt) format.
It is basically a stripped down version of Word2Any.exe, with limited input formats and a single output format.


• Oops, a bug in GetSystemInformation.exe was fixed: it still accepts wildcards, but the specified argument must now match the complete property name, not just part of it (e.g. GetSystemInformation.exe window* will no longer return a match, while the previous version did return ActiveWindowTrackingDelay, DragFullWindows, PenWindows, etc.).


GetSystemInformation.exe had a minor update: it now accepts wildcards, e.g. GetSystemInformation.exe mouse*


• I wish you all a happy and healthy new year.



Archived News pages
Archived news from 2021
Archived news from 2020
Archived news from 2019
Archived news from 2018
Archived news from 2017
Archived news from 2016
Archived news from 2015
Archived news from 2014
Archived news from 2013
Archived news from 2012
Archived news from 2011
Archived news from 2010
Archived news from 2009
Archived news from 2008
Archived news from 2007



page last modified: 2022-04-18