Rob van der Woude's Scripting Pages


Writing batch files with Notepad

Windows' own Notepad may be the easiest editor available for writing batch files.
Since you probably used it before, at least it doesn't have a "steep learning curve".

Be aware, though, that extended ASCII characters entered in Notepad may sometimes result in completely different characters in the resulting batch file. A tip mailed to me by Denis St-Pierre is to use the good old EDIT command to create a batch file with extended ASCII characters like accented letters or "border lines".
I use File Commander's editor myself for the same reason. This would suggest that any "text mode editor" could do the trick. I can confirm that COPY CON filename and ECHO accented_text > filename do.


Convert Unicode to ASCII

When saving a file through the "Save As" dialogue, you can use the "Encoding" field to choose between plain ASCII (ANSI) or Unicode.
So if you open a plain ASCII text file in Notepad, you can save it in Unicode and vice versa.

See the Unicode section of my TYPE page if you need to convert ASCII and Unicode from the command line.


Printing text files

Notepad's /P switch is perfect for printing text files from the command line:

NOTEPAD /P text_file

will open text_file in Notepad, send it to the default printer without any user interaction, and close Notepad again.
This works with all plain text files, both ASCII and Unicode.


Force notepad to read files as ASCII text

Notepad's /A switch can be used to make sure a file is loaded in Notepad as plain ASCII:

NOTEPAD /A ascii_text_file


Keeping log files with Notepad

Judith Porsch taught me the following trick:
If you create a new text file in Notepad and insert a line containing only the "word" .LOG at the top of the file, Notepad will append a line with the current date and time and move the cursor to the last line each time you open the file.


Change headers and footers in Notepad's printout

Huub van de Pol e-mailed me the following tip:
Sometimes it may be inconvenient to print the default page header and footer in Notepad. You can change the print settings, but Notepad by default does not save these modified settings.
The following REG file, when imported in the registry, changes this behaviour:



The first key, fSavePageSettings, when set to 1, will make Notepad keep the last print settings.
The keys "szHeader" and "szTrailer" are used to set the page header and footer respectively. In this particular example their values are blank strings, so no header and footer will be printed.

Before making these changes, you may want to save your current Notepad settings first by using the following command:

REGEDIT /E C:\NotepadDefaults.reg "HKEY_CURRENT_USER\Software\Microsoft\Notepad"

If you ever need to restore the original default settings, just doubleclick the file C:\NotepadDefaults.reg created with this command.

page last modified: 2016-09-19; loaded in 0.0020 seconds