Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Batch file help

48 views
Skip to first unread message

Bible John

unread,
Sep 20, 2005, 1:46:32 AM9/20/05
to
I use Windows 98SE on a Pentium II laptop.

Ever since Windows 3.11 I have been writing batch files for all kinds of
uses. I miss 3.11 in some ways as I had more control over the computer from
DOS and yes Scandisk cannot be run in 98 from DOS (like it could in 3.11).

I was trained in DOS 6.22 under Windows 3.11, and boy oh boy I miss that old
DOS environment! Its one of the reasons why I'd love to buy myself a spare
HP 200LX DOS palmtop (I am limited in my room for extra desktops and
laptops).

The batch file called Backup.bat. I execute the batch file from DOS. What
improvements could I make to it? I miss writing many batch files (something
I used to do often in 3.11).

\@echo off
REM scandisk /all /autofix /nosave /nosummary
cls
cd\
deltree /y \backup\
echo D| xcopy C:\mydocu~1\*.* /e /h /k C:\backup\MYdocu~1\
cd\
cls
echo D| xcopy /h C:\autoexec.bat C:\backup\autoexec
echo D| xcopy /h C:\config.sys C:\backup\config
echo D| xcopy /h C:\windows\user.dat C:\backup\registry\
echo D| xcopy /h C:\windows\system.dat C:\backup\registry
cls

William Allen

unread,
Sep 20, 2005, 10:14:13 AM9/20/05
to
"Bible John" wrote in message

> I use Windows 98SE on a Pentium II laptop.
>
> Ever since Windows 3.11 I have been writing batch files for all kinds of
> uses. I miss 3.11 in some ways as I had more control over the computer from
> DOS and yes Scandisk cannot be run in 98 from DOS (like it could in 3.11).

That is not true. You can run ScanDisk non-interactively from a Batch
file in an MS-DOS box in the GUI (which I assume is the way you are
working from my comment below) and also get ERRORLEVELs returned which
the Batch file can act upon.

In Advanced Options for ScanDisk, set "Display summary only if errors
found" (or set "Never" if you are checking ERRORLEVELs in your Batch
file) and use:

start /wait scandskw /n

For other ScanDisk or ScanDskw switches:

=====Extract from Windows 95 Resource Kit Helpfile
Syntax

scandskw [drive:] [/A] [/N] [/P]
scandisk drive:\dblspace.nnn
scandisk drive:\drvspace.nnn

Parameters

drive:

Specifies one or more drives to be checked.

/A or /All

Checks all local, nonremovable hard disk drives.

/N or /NonInteractive

Starts and closes ScanDisk automatically. However, this switch does
not prevent ScanDisk from stopping to report errors found on the
drive.

/p or /Preview

Runs ScanDisk in Preview mode, where it reports and seems to correct
errors that it finds, but it does not actually write changes to the
disk.

Important When running scandskw in Preview mode, it appears as though
ScanDisk is fixing errors, but it is not. Also, notice that unlike
other settings in ScanDisk, the /Preview switch is not saved in the
Registry, so the next time you run ScanDisk, it is no longer in
Preview mode.

To determine whether ScanDisk is running in Preview mode, look for the
tag “(Preview)” in the caption of the main ScanDisk window.

dblspace.nnn or drvspace.nnn

Checks the specified unmounted DoubleSpace or DriveSpace compressed
volume file, where nnn is the filename extension for the hidden host
file.

The following table describes the codes provided when ScanDisk
finished running.

Exitcode Description
0 Drive checked, no errors found
1 Errors found, all fixed
250 Check could not start — cannot load or find DSKMAINT.DLL
251 Check could not start — insufficient memory
252 Errors found, but at least some were not fixed
253 At least one drive could not be checked
254 Check was canceled
255 Check was terminated because of an error

You can capture the exit code in a batch file to define an action to
take in the event of particular exit code. For example:

start /w scandksw c: d: /n
if errorlevel exitcode goto command
...

In this sample, start /w forces the batch file to stop and wait for
scandskw to finish (otherwise, because it is a Windows-based program,
the batch file would continue as soon as scandskw had been launched).
Also in this example, if the actual exit code is greater than or equal
to the exit code specified by exitcode, the batch file runs the
specified command; otherwise, it continues to the next line in the
batch file. The goto command entry could specify any command you want.
=====Extract from Windows 95 Resource Kit Helpfile ends

...snip


> The batch file called Backup.bat. I execute the batch file from DOS. What
> improvements could I make to it? I miss writing many batch files (something
> I used to do often in 3.11).
>
> \@echo off

(the \ is a syntax error)

> REM scandisk /all /autofix /nosave /nosummary
> cls
> cd\

It's unnecessary to make root folder current since you specify folder
paths in your Batch commands.

> deltree /y \backup\
> echo D| xcopy C:\mydocu~1\*.* /e /h /k C:\backup\MYdocu~1\
> cd\

It's unnecessary to make root folder current yet again since you
specify folder paths in your Batch commands.

> cls
> echo D| xcopy /h C:\autoexec.bat C:\backup\autoexec
> echo D| xcopy /h C:\config.sys C:\backup\config
> echo D| xcopy /h C:\windows\user.dat C:\backup\registry\
> echo D| xcopy /h C:\windows\system.dat C:\backup\registry
> cls

I assume you are working in an MS-DOS box in the GUI, since you
are using the xcopy /H switch (not valid in real-mode MS-DOS).

Your posted script isn't really a backup process, since you remove
the existing backup before making a new one. Any data problems that
have occurred since the last backup and that cause the script to stall
would leave you without a backup _and_ without valid data.

Moreover, if you write the XCOPY commands properly (use /i switch
or a trailing wildcard), you don't need the pipe for D=Directory
replies. Typical syntax for each XCOPY command would be:

xcopy /y C:\AUTOEXEC.BAT C:\BACKUP\AUTOEXEC\*.* >NUL
IF ERRORLEVEL 1 GOTO ERROR

and at label :ERROR you could have suitable error handling code.

--
William Allen
Free interactive Batch Course http://www.allenware.com/icsw/icswidx.htm
Batch Reference with examples http://www.allenware.com/icsw/icswref.htm
From email address not checked. Contact us at http://www.allenware.com/


Bible John

unread,
Sep 20, 2005, 11:34:23 AM9/20/05
to
Thanks for the advice William. I am a bit rusty on Batch file creation, and
my MSDOS book is at home 250 miles away. No I have not been able to find
such a equilivent book in todays Windows market. The DOS Book I had was
like 600 pages and covered everything. It was used at my college in thier
DOS courses.

Would you be able to kindly rewrite my batch file to accomplish the same
thing, but perhaps in not so much time? It really takes like 15-20 minutes
to complete the batch file.

Todays Windws market cares little about DOS, so this would explain the
dumbing down of DOS books.

Thank you,


John


"William Allen" <_w...@email.com> wrote in message
news:43301a51$0$97135$ed26...@ptn-nntp-reader03.plus.net...

> 250 Check could not start - cannot load or find DSKMAINT.DLL
> 251 Check could not start - insufficient memory

Richard Bonner

unread,
Sep 20, 2005, 1:54:17 PM9/20/05
to
Bible John wrote:
> Thanks for the advice William. I am a bit rusty on Batch file creation,

*** William has a batch file tutorial, as do I and other regulars here.
Mine is at:
http://www.chebucto.ca/~ak621/DOS/Bat-.html


For others, see the Batch File section at:

http://www.chebucto.ca/~ak621/DOS/Websites.html

(If any regulars here have DOS websites that are not listed, e-mail me
and I will include links to them.)


> my MSDOS book is at home 250 miles away. No I have not been able to find
> such a equilivent book in todays Windows market.
>

> John

*** They don't have any. Even Microsoft doesn't give much DOS
information in the manuals that come with Windows. This is despite the
fact that they include DOS or a DOS emulator with Windows.


> The DOS Book I had was like 600 pages and covered everything. It was

> used at my college in their DOS courses.

*** There are many DOS tutorials and help guide available. See the
previous URL I gave. That aside, go to used book stores. There are often
DOS books there. Despite their age, they are still very useful for most
DOS versions today.

Richard Bonner
http://www.chebucto.ca/~ak621/DOS/

PS: Please don't top post.

R.

William Allen

unread,
Sep 20, 2005, 2:25:11 PM9/20/05
to
"Bible John" wrote in message
> Thanks for the advice William. I am a bit rusty on Batch file creation, and
> my MSDOS book is at home 250 miles away. No I have not been able to find
> such a equilivent book in todays Windows market. The DOS Book I had was
> like 600 pages and covered everything. It was used at my college in thier
> DOS courses.
>
> Would you be able to kindly rewrite my batch file to accomplish the same
> thing, but perhaps in not so much time? It really takes like 15-20 minutes
> to complete the batch file.
>
> Todays Windws market cares little about DOS, so this would explain the
> dumbing down of DOS books.

Frankly, Windows runs MS-DOS Batch files far better than MS-DOS
ever did. As for writing a Backup Batch file, how to write a fully-featured
Backup Batch file is covered in great detail (and used as the basis
to teach Batch file writing including nearly a thousand interactive
exercises) in our Batch File Course. Start with the Introduction.
Syllabus and Index to Lessons: http://www.allenware.com/icsw/icswidx.htm

The Course is specifically aimed at Windows 95/98/ME users.

Richard Bonner

unread,
Sep 20, 2005, 3:22:43 PM9/20/05
to
William Allen wrote:

> Frankly, Windows runs MS-DOS Batch files far better than MS-DOS
> ever did.

> --
> William Allen

*** How so? I found just the opposite, and even more so now that I run
newer DOS versions and newer updated commands.

Richard Bonner
http://www.chebucto.ca/~ak621/DOS/

William Allen

unread,
Sep 20, 2005, 3:44:47 PM9/20/05
to
"Richard Bonner" wrote in message

> William Allen wrote:
>
> > Frankly, Windows runs MS-DOS Batch files far better than MS-DOS
> > ever did.
> > --
> > William Allen
>
> *** How so? I found just the opposite
...snip

No. Compared with older MS-DOS real-mode Batch operations, working
in Windows 95/98/ME GUI MS-DOS boxes is far better and more efficient.
This note - posted many times before - details some of the many
improvements in Windows 95/98/ME Batch-related operations compared
with MS-DOS 6.22. The use of the GUI MS-DOS Box also simplifies
teaching the MS-DOS Batch Language.

Obviously, Windows 2000/XP Batch operations are far more advanced
still and allow much easier coding for many operations, but this note is
for Windows 95/98/ME only:

In no special order:

==1) START command
Type:
start /?
at the DOS prompt for simple details. This starts a new process
in a separate Window. If you START a Batch file this way, Windows
passes the full short-name alias path in the %0 position, which
trivially solves the traditional "hard" legacy Batch problem of
finding the full path of the current script.

Also note that if you use, say
start /wait GUIProgram
then, if the GUIProgram returns informative ERRORLEVELs,
as for example ScanDisk does (see the Windows Resource
Kit Helpfile for the list of ERRORLEVELs it returns), then
START returns the ERRORLEVEL to your calling Batch file.

This is very useful for batch operations.

If you use:
start GUIProgram
you will normally see only an uninformative 0

(BTW, at any DOS prompt, use the syntax
CommandName /?
to get brief help with most commands)

==2) Long File Names
Long file names are available in the GUI. Always use
"quotes" around any that contain [Space] characters.

Eg:
copy /y "c:\path to\File with a long name.ext" "c:\program files"

But note you can use "quotes" around all file names
if you wish. Or even around just that part of the name
that contains [Space]s if that's more convenient (but this
partial quoting fails for some commands, such as attrib,
so partial quoting is best avoided when possible).

Long file names enable many new Batch techniques.

==3) LFNFOR in Win95/98/ME
Type LFNFOR /? for details

This toggles FOR IN DO to return Long File Names.

Notes:
Where a wildcard is used in the FOR IN DO parenthesis
and the wildcard contains a pathspec as well as a filename
spec _only_ the first search target returned has the full long
name path. All the rest that follow are stripped of the
pathspec. This is useful for some parsing operations
and can also be used in loops to distinguish between
first and subsequent passes through the loop.

==4) "Quoted string" handling improved in Win95/98/ME
Text in "quotes" is read as a single one-piece token. For example,
when used on the command-line "quoted text including spaces" is
passed to your script as a single parameter.

a) so you can pass a "Very Long Parameter in the first position"
to a Batch script and it will be loaded entirely into the %1 pointer,
eg:

Myscript "Very Long Parameter in the first position"

b) You can use a FOR IN DO loop to remove quotes from strings
FOR %%F IN ("This could be a variable's contents") DO SET MYVAR=%%F
sets
MYVAR=This could be a variable's contents

Notice that, unlike legacy DOS, FOR IN DO in Windows 95/98/ME
handles "quoted text" as a single token instead of breaking it up.

c) You can use > and >> inside quotes in a FOR IN DO loop to
initialise a file and append to it on the same line:
C:\WORK>FOR %%F IN ("Line one>" "Line two>>" "Line three>>") DO ECHO.%%Fmyfile

C:\WORK>ECHO.Line one>myfile

C:\WORK>ECHO.Line two>>myfile

C:\WORK>ECHO.Line three>>myfile

C:\WORK>type myfile
Line one
Line two
Line three

==5) FOR IN DO capitalisation
A FOR IN DO loop capitalises text tokens preceded with / for example:

C:\WORK>FOR %%F IN (/switch1 /switch2 /switch3) DO ECHO. %%F

C:\WORK>ECHO. /SWITCH1
/SWITCH1

C:\WORK>ECHO. /SWITCH2
/SWITCH2

C:\WORK>ECHO. /SWITCH3
/SWITCH3

(This simplifies writing Batch files to accept case-insensitive switches)

There are many other uses of the improved FOR IN DO loop, too.

==6) XCOPY in Win95/98/ME
Extensive improvements to XCOPY were made. In the GUI
check the command XCOPY /? for all the many extra switches.

Additionally, XCOPY now replaces COMMAND /F (the fail-continue
shell command) for drive ready checking. For example the
one-liner:
xcopy a:\NUL>NUL
gives no text output to screen but instead returns:
Return code (ERRORLEVEL): 4
if the drive is not ready or contains unformatted disk

Return code (ERRORLEVEL): 5 if the drive is ready
(the 5 return code means: couldn't find file - which is
correct for the formal NUL file)

(In legacy DOS, although the XCOPY command reported
ERRORLEVELs in these circumstances, it stalled with
Abort/Retry/Fail unless used in a COMMAND /F shell, and
because the parent shell doesn't inherit these values,
workarounds were needed to grab them. This bug was
fixed in Windows 95/98/ME)

==7) Variable expansion in immediate mode
Unlike legacy DOS, in Win95/98/ME you can type
variable expansions at the command line and they
are interpreted correctly. This is very useful for people
learning how to use variables, because they can check
commands using them at the prompt to watch how
they're executed:
C:\WORK>set test=ECHO. This variable expands

C:\WORK>%test%
This variable expands

==8) REN now operates on foldernames as well as filenames

==9) MOVE will move entire folder hierarchies to new folders,
instead of being restricted to simple renaming within the
existing subfolder folder hierarchy (this latter task now taken
over by REN)

==10) Return-code (ERRORLEVEL) shell
A new switch /Z was added to COMMAND.COM to document
ERRORLEVELs. If you run a child shell with this command:

COMMAND /z /k prompt RCode $p$g

all subsequent changes to the ERRORLEVEL byte are documented
on screen (including intermediate values during pipe operations)
so you can check any command or pipe operation quickly and
easily to see the ERRORLEVEL codes returned. These take
values between 0 and 255 (decimal) and are used by many
programs to return information about their operation, or success
or failure. Type the command EXIT to exit the Return-code shell.
The "Prompt RCode $p$g" is optional as a reminder; on exit,
your normal prompt will be returned. This shell is very useful
for learning about ERRORLEVELs, and is superior to using
a separate Batch file to determine the current ERRORLEVEL
since you can turn on the Return Code shell and run a batch
file and watch the ERRORLEVEL changes as it runs without
needing to change the batch file you're investigating.

==11) CSCRIPT batch interface
There is an interface program CSCRIPT.EXE installed with
WSH (default install in Win98/ME, free download for Win95)
that allows batch files full access to a programmable interface.
WSH (Windows Script Host) main page for information:
http://msdn.microsoft.com/scripting/

The use of Windows Script Host largely eliminates the need
for any third-party utilities in Batch operations.

Todd Vargo

unread,
Sep 20, 2005, 5:19:28 AM9/20/05
to

"Bible John" <john.d...@x-files.gov> wrote in message
news:jmNXe.23227$tc7....@fe03.lga...

First of all, DOS 6.22 had a BACKUP.EXE program, so BACKUP.BAT would be a
poor choice of file name. BU.BAT would be more appropriate. But since this
is for Windows 98, that's not a problem. Second, a backup on the same drive
is not a safe backup. It's just an extra copy. Third, Windows 98 already
creates backups of the files listed above for you. Look in
c:\windows\sysbckup for files named rb000.cab. Windows 98 stores those files
in a series of compressed cabinet files. IIRC, SCANREGW.EXE creates these
.cab files on the first successful boot of each day.

Note 1: Since SCANDISK is a Windows program, you would run this batch in
Windows. I would move the scandisk command to the end to make backups before
scandisk makes changes to the drive.

The cd\ and cls commands don't do anything as far as this batch is
concerned. You could also eliminate the need to pipe the "D" to xcopy if you
terminate the destination with a backslash. Also, for ease in readability
you might place the xcopy switches at the end of the xcopy commands.

Note 2: In Windows 98, you can use file names with spaces if enclose them in
quotes.

@echo off
cls
deltree /y C:\backup\
xcopy C:\mydocu~1\*.* "C:\backup\MY Documents\" /e /h /k
xcopy C:\autoexec.bat C:\backup\ /h
xcopy C:\config.sys C:\backup\ /h
xcopy C:\windows\user.dat C:\backup\registry\ /h
xcopy C:\windows\system.dat C:\backup\registry\ /h


REM scandisk /all /autofix /nosave /nosummary

Note 3: There are a number of other useful utilities besides scandisk in
Windows 98. IMO, the Windows Maintenance Wizard (C:\WINDOWS\TUNEUP.EXE)
would be a better choice.

Note 4: With Windows 98, you can boot to pure DOS by pressing [Shift]+[F5]
or [F8] at the beginning of the boot process and selecting the Boot to
Command Prompt Only option.

--
Todd Vargo (double "L" to reply by email)

Richard Bonner

unread,
Sep 21, 2005, 7:18:51 AM9/21/05
to
William Allen wrote:
> "Richard Bonner" wrote in message
> > William Allen wrote:
> >
> > > Frankly, Windows runs MS-DOS Batch files far better than MS-DOS
> > > ever did.
> > > --
> > > William Allen
> >
> > *** How so? I found just the opposite
> ...snip

> No. Compared with older MS-DOS real-mode Batch operations, working
> in Windows 95/98/ME GUI MS-DOS boxes is far better and more efficient.
> This note - posted many times before - details some of the many
> improvements in Windows 95/98/ME Batch-related operations compared
> with MS-DOS 6.22.

(Snip)

*** Thanks for reposting that, William. I was familiar with much of
that from my Windows days, but many of the improvements you listed were
done for Windows'sake, not DOS'.

My comment was regarding batch files in general. I found them to run
faster and with less interference from Windows when on a stand-alone
system, at least as far as WIn 95 & 98 were concerned.


> The use of the GUI MS-DOS Box also simplifies
> teaching the MS-DOS Batch Language.

*** Could you elaborate?


> Obviously, Windows 2000/XP Batch operations are far more advanced
> still and allow much easier coding for many operations,

> --
> William Allen

*** Yup. Some of those improvements are excellent in that they often
simplify batch file coding down to just one line.

Richard Bonner
http://www.chebucto.ca/~ak621/DOS/

William Allen

unread,
Sep 21, 2005, 9:20:34 AM9/21/05
to
"Richard Bonner" wrote in message
> William Allen wrote:
...snip

> > The use of the GUI MS-DOS Box also simplifies
> > teaching the MS-DOS Batch Language.
>
> *** Could you elaborate?

See: http://www.allenware.com/icsw/icsw000.htm where the student
creates the customised GUI MS-DOS Box which makes the entire
interactive Batch Course possible.

Richard Bonner

unread,
Sep 22, 2005, 11:26:10 AM9/22/05
to
William Allen wrote:
> "Richard Bonner" wrote in message
> > William Allen wrote:
> ...snip
> > > The use of the GUI MS-DOS Box also simplifies
> > > teaching the MS-DOS Batch Language.
> >
> > *** Could you elaborate?

> See: http://www.allenware.com/icsw/icsw000.htm where the student
> creates the customised GUI MS-DOS Box which makes the entire
> interactive Batch Course possible.
> --
> William Allen

*** Ahh, yes. I misunderstood your statement. I didn't clue in that you
were talking about your interactive course.

Richard Bonner
http://www.chebucto.ca/~ak621/DOS/

0 new messages