Using Release 5 in DOS/NT batch files

Purpose of this sheet

This document explains how the command line version of Maple V Release 5 can be used in DOS/NT 4.0 batch files.

For example, I abuse R5 to convert filenames to lower case which is important when transferring files that have been created with Windows 16-bit applications to UNIX based operating systems. Windows 16-bit applications, e.g. Lotus Ami Pro 3.1, create files with upper case filenames, so if a file called MPLBATCH.HTM is uploaded to a UNIX webserver and if it is being linked in an HTML file with the tag <A HREF="mplbatch.htm"> (a lower case filename), it cannot be found. Likewise Maple library files created with the DOS march utility have upper case filenames so they cannot (should not) be found by Maple V running on a case-sensitive platform.

The DOS batch file

I use the following Windows NT 4.0 batch file called tolower.bat to prepare files to be uploaded to my websites:

The first five lines in the batch file switch off printing and cause the batch to jump to the section containing information on the usage of tolower.bat if one of the following help argument has been passed to it: /?, /h, or --help:

if "%1"=="/?" goto help
if "%1"=="--help" goto help
if "%1"=="/h" goto help
The following line calls the DOS command line version of Release 5 withthe -q switch which suppresses printing, and the -b option which indicates the path to the R5 main Maple Library. (I have to pass the -b switch for otherwise, the command line version of R5 does not initialize on my PC.)

The first -c option is used to pass (read) the Maple text file c:/tools/batch/tolower.mv5 containing the Maple code to convert filenames (see below).

In order to execute the statements in the file, a second -c switch has to be passed to R5 which calls the function tolower with the first argument (%1) passed to the NT batch file. This first batch file argument indicates the directory including the files to be renamed. tolower expects an argument of type string or name, so backquotes enclose the %1 tag. If no argument is passed to the batch file, the filenames in the current working directory are renamed.

Finally the third -c switch tells R5 to quit after the call to tolower has been executed. The quit command must not be included in tolower.mv5 because this would terminate R5 before a call to tolower (second -c switch) can be executed. (The calling statement to R5 should be in one line, it is split here for proper display.)

e:\maplev5\bin.wnt\cmaple -q -b e:\maplev5\lib
-cread(`c:/tools/batch/tolower.mv5`) -ctolower(`%1`) -cquit
The following goto statement tells NT to jump to the end of the file, thus terminating the batch. The :help label is a mark for displaying some text on screen if no argument has been passed to tolower.bat
goto :EOF

   echo function: converts all filenames in a directory to lower-case filenames
   echo usage:    tolower _path_, where _path_ is input with slashes; if no path 
   echo              is given, the files in the current directory are renamed
   echo Examples: tolower c:/maplev3
   echo           tolower

The Maple text file

As mentioned above, tolower.bat causes Maple to read in the file tolower.mv5. The latter file contains the following code and uses the utils package which contains the functions replace, dir and toLower:
tolower := proc()
   local dir, i, command;
   # if no argument has been given, determine the current working directory 
   # in the DOS shell
   if args[1] = `` then
      dir := currentdir()
      dir := args[1]
   # utils/replace slashes in the path to the directory with backslashes:
   dir := readlib(`utils/replace`)(args[1], `/`=`\\`): 
   # utils/dir returns the files in direcory dir 
   for i in readlib(`utils/dir`)(dir) do
      # create the DOS rename command for each file in dir
      command := cat(`rename `, dir, `\\`, i, ` `, readlib(`utils/toLower`)(i));
      # print the file currently being renamed on screen, use slashes
      # instead of backslashes
      lprint(readlib(`utils/replace`)(command, `\\`=`/`));
      # execute the DOS rename command

Using the new batch file

Suppose the files to be renamed are in subdirectory e:/copy3:
E:\copy3>ls -l
total 6
-rw-r--r--   1 544      everyone     4080 Oct 24 19:07 MPLBATCH.HTM
-rw-r--r--   1 544      everyone     7155 Oct 24 13:23 MPLJSR.HTM
In a DOS shell the tolower batch file is executed with the following command:
E:\copy3>tolower e:/copy3
rename e:/copy3/MPLBATCH.HTM mplbatch.htm
rename e:/copy3/MPLJSR.HTM mpljsr.htm

E:\copy3>ls -l
total 6
-rw-r--r--   1 544      everyone     4080 Oct 24 19:07 mplbatch.htm
-rw-r--r--   1 544      everyone     7155 Oct 24 13:23 mpljsr.htm

The files for download


MPL BATCH 1.1 as of January 02, 2000
Author: Alexander F. Walz,
Original file location: