HOME
TOPICS
ABOUT ME
MAIL

 
The ultimate in DOS automation: This batch file creates a batch file if it doesn't already exist and then opens it in an editor.
  technofile
Al Fasoldt's reviews and commentaries, continuously available online since 1983

Batch file project: A batch file that creates and edits batch files.


By Al Fasoldt
Copyright © 1997, Al Fasoldt


   Please read this introduction if you are unfamiliar with batch files. The batch file is listed after this introduction. (Experienced DOS users can skip this section.)

   
   Batch files are texts that contain instructions for the MS-DOS command processor. They are texts that contain the same kind of commands that you could type on the DOS command line, either in a DOS window while running Windows or when the PC is running only DOS.
   Create a batch file using Notepad or any other editor (or, less suitably, a word processor) with word-wrap turned off. Save the file as a text using the name listed above in big type. Make sure the file has a .BAT filename extension, like this: MYFILE.BAT. You can cut and paste from your browser window to create the batch file listed here.
   You run a batch file by typing the first part of its name from a DOS command line or from another batch file. To run MYFILE.BAT, you'd type "MYFILE" at the command line, or you'd run it from a batch file with a line that says the same thing. You should make sure that all your batch files are located in the path that MS-DOS uses. This could be "C:\Windows\Command" under Windows 95 or "C:\DOS" under Windows 3.1 and 3.11, or it could be a special folder (called "BAT," maybe) somewhere else. If you use a special folder, make sure the location of that folder is part of the path statement in your PC's AUTOEXEC.BAT. (Note well: If you have Windows 95, you do not need to do anything fancy; just put the batch folder's name in the AUTOEXEC.BAT this way:
  SET PATH=C:\BAT
and leave out the "C:\Windows; C:\Windows\Command" stuff entirely. Windows 95 ALWAYS puts its own folders in the path.)
   
********** BATCH FILE BEGINS HERE. **********

@echo off

goto top

:help

cls

echo.

echo bat.bat, to automate creation, editing and last-copy backup of batch files.

echo Al Fasoldt 9-26-97, revised 12-05-97.

echo Windows 95 only!

echo.

echo Assumes that EDIT.COM or EDIT.EXE are in the path,

echo and that c:\bat is where batch files are kept.

echo If your batch files are kept somewhere else, change the path below,

echo or just change all references from c:\bat to c:\windows\command.

echo (I recommend c:\bat. Make sure c:\bat is in the PATH statement in

echo in your autoexec.bat.)

echo.

echo USAGE:

echo Run with name of batch file (new or existing) as parameter, as in

echo [bat makedupe]. (Special case: [bat auto] or [bat autoexec].)

echo.

goto end

:auto

copy /Y c:\autoexec.bat c:\bat\batchbak

edit c:\autoexec.bat

cls

goto end

:top

if %1()==() goto help

if %1==/? goto help

if %1==? goto help

if not exist c:\bat\nul md c:\bat

if not exist c:\bat\batchbak\nul md c:\bat\batchbak

if %1==auto goto auto

if %1==autoexec goto auto

if not exist c:\bat\%1.bat goto new

copy /Y c:\bat\%1.bat c:\bat\batchbak >nul

edit c:\bat\%1.bat

cls

goto end

:new

copy c:\bat\box c:\bat\%1.bat >nul

edit c:\bat\%1.bat

cls

:end


        
********** BATCH FILE ENDS HERE. **********