Tuesday, 15 October 2013

CALL

Sometimes it's handy to be able to run one batch file from another. Until DOS 3.3 you had
to resort to tricks to do that; without the tricks when you called a second batch file from a first then control would transfer to the second and you'd never get back to the first.

The command: CALL d:path\FILE NAME parameters
can be used in DOS versions 3.3 and later to start a second batch file from a parent and then return to the parent after the second finishes. Note: Do not use pipes or redirection on the second file.

The FILE NAME is the name of the second batch file; the parameters are any options that
the second file requires to properly run. When the second batch file terminates, control is returned
to the first batch file on the line following the CALL command.
You can simulate CALL in DOS versions lower than 3.3 by using:
COMMAND /C d:path\FILE NAME parameters In DOS 3.3 and later you can selectively cause lines in a batch file from being displayed. To cause this, place an "@" sign in front of the line in question.
One use of this would be to suppress showing the "ECHO OFF" command which is the
starting command of many batch files. Until the ECHO OFF command is actually executed, ECHO is ON and the command shows. To stop even this from showing make the first command: @ECHO OFF.

If you need to use the "@" feature with a command that already starts with @ (e.g.,
@WIP.EXE) then use a double @ (e.g., @@WIP) in the batch file (this should be rare).
Below are some simple batch file examples to whet your appetite.

Saturday, 22 June 2013

FOR..IN..DO

This command is similar to the programmer's FOR..NEXT loop in that a particular action
can be repeated a given number of times. The syntax (which may look a bit complicated) is:
FOR %%Variable IN (Set) DO Command
%%Variable is one-letter with the mandatory %% before it. Two percentage signs are used
so this variable won't be confused with a marker.
(Set)  is  one  or  more  filenames  or  commands  you  want  %%Variable to  assume  while  the
command is being executed. Use a space between entries, and pathnames are allowed. Don't forget
the parenthesis around the set. Wildcards may be used within (Set) if you are using filenames.
Command  is  the  particular  DOS  command  or  batch  subcommand  you  want  to  have  performed.
Usually one or more of these commands will contain the %%Variable in it. If (Set) contains DOS
commands, only %%Variable is used.
In effect, what this subcommand does is cause %%Variable to be an index into the (Set) for
use by Command.
An example:
Problem:Compare all files on the disk in drive A: with those on the disk in  drive B: and report
those that match.
Answer:The following two-line batch file run from the A: drive will do that task:
ECHO OFF
FOR %%Z IN (*.*) DO IF EXIST B:%%Z ECHO %%Z is on A: and B:
Let's see how...
The first line turns command display off to clear the clutter.
The second line is executed as many times as there are files on the disk in A: [the set (*.*)
assures this]. Each of those filenames are assigned to %%Z in turn and then checked for presence
on drive B: with the EXIST logical statement. If EXIST is true, then the message at the end of the
IF subcommand is sent to the screen, otherwise nothing is printed  and the next file on drive A: is
assigned and checked.
The following will diagram this process...
Files on drive A:
COMMAND.COM
FILE.ONE
FILE.TWO

Files on drive B:
COMMAND.COM
FILE.ONE
FILE.LTR
The batch subcommand we are investigating is:
FOR %%Z IN (*.*) DO IF EXIST B:%%Z ECHO %%Z is on A: and B:
Each  filename  on  A:  is  substituted  in  the  IF  subcommand  and  then  executed.  To  get  the
same effect you would have to type:
IF EXIST B:COMMAND.COM ECHO COMMAND.COM is on A: and B:
IF EXIST B:FILE.ONE ECHO FILE.ONE is on A: and B:
IF EXIST B:FILE.TWO ECHO FILE.TWO is on A: and B:
In the case of the example above, the first two would have a positive response and the last
would not print anything. Study it carefully before going on!
Another example:
Files on drive A:
COMMAND.COM
FILE.ONE
FILE.TWO
Files on drive B:
COMMAND.COM
FILE.ONE
FILE.LTR
OK, told you to study the example. Let's see if you remember. What is the oneline batch file
command to find and report out all files starting with an "F" on drive A:?
FOR %%Z IN (A:F*.*) DO ECHO File %%Z is on drive A:
In this case you see that the A: disk is checked for any file starting with the letter "F" and
that name is substituted in the variable %%Z. The appropriate message is then printed.
This is not an easy concept. It will require some study and practice to master.
Let's now look at using DOS commands in (Set).
The (Set) can contain DOS commands instead of filenames and these commands will then
be executed in sequence (to include running large programs under the control of the FOR..IN..DO
loop).
Let's say you want to sequentially:
•  Clear the screen,
•  Show the DOS version number,
•  then Show a disk directory with pause on.
You could do all that in a one line batch file with the following command in it:
FOR %%T IN (CLS Ver Dir/P) DO %%T 


When using DOS commands in (Set) you must use the space as a delimiter and cannot have
the  asterisk  (*)  or  question  mark  (?)  in  any  command.  Use  a  colon  (:)  instead  of  a  space  when
passing parameters to programs (i.e., DBASE:FILE instead of DBASE FILE). [The colon trick does
not always work; you have to experiment.]
It is possible to issue the FOR..IN..DO command at the DOS prompt by dropping one of the
percentage signs (%) on the variable.

Sunday, 3 March 2013

SHIFT

The limit of 10 parameters for a batch file can be raised through use of the SHIFT
command. The syntax is the single word:

When that sub command is encountered, all parameter/marker pairings are shifted one to the
left. Whatever was assigned to %0 is lost, the contents of %1 are moved to %0, %2 moves to %1 ...
%9 moves to %8 and a new parameter from the command line is moved into %9.
While this brings in a new parameter, all have shifted and you must anticipate the effect on your
batch file "program."
The effect of SHIFT:



Remember, this command seems very simple, but its effects are far ranging and the logical
consequence of mismatching parameters and markers and be disastrous!

Saturday, 2 February 2013

Password Example

The following batch file can be used to establish a password for running a program. The
batch file is named START.BAT and calls the program named WP.COM.
ECHO OFF
IF %1==XYZ GOTO GOOD
ECHO BAD PASSWORD...ENDING
GOTO END
:GOOD
ECHO YOU'RE OK...STARTING
WP
:END
Below you'll see the response of the computer to various commands...
First the bad password. At the prompt type START ABC.
A>START ABC
A>ECHO OFF
BAD PASSWORD...ENDING
A>_
Now use the correct password. Type the correct command at the prompt.
A>START XYZ
A>ECHO OFF
YOU'RE OK...STARTING
At this point the WP program starts. You don't see the command because echo is off.

IF

The IF subcommand allows you to make decisions within your batch file. Its syntax is:
IF Condition Command where,
Command = Any legal DOS command or batch file subcommand
Condition = One of three tests that yield true or false:
1. The ERRORLEVEL of a program.
2. Two strings are equivalent.
3. A file exists in the current directory.
Unlike programming languages, which allow many logical tests in an IF statement, the batch
IF statement is limited to only the three above.
Condition 1: ERRORLEVEL is a number that indicates to DOS whether the last program
run was successful.

A zero (0) indicates a good run, anything above zero indicates an error condition. (Only
DOS commands BACKUP and RESTORE have an exit code.)
You can create small programs to capture the keyboard output and report it as an error level
(see Batch Sample #3 later).
Condition 2: String comparison is indicated by double equal signs:
String1 == String2
compares the two strings.
This comparison is often used with parameters and markers to check for a particular entry.
For example,
IF %1 == 40 MODE C40
checks parameter one for 40 and, if found, changes the display to 40-columns wide.
Condition 3: The logical test checking for a file has the format:
EXIST d:Filename
You can use this test to check and see if a DOS disk is in the active drive (as one example).
Another use might be to check for a particular file to see if the user has a valid disk in the drive.
Pathnames are NOT allowed.

GOTO

The format for this command is:

GOTO LABEL

where LABEL is a line in your batch file that starts with a colon (:) followed by up to an eight
character name (actually, you can type any number of characters, but DOS only recognizes the first
eight).
Want to create an endless loop? GOTO gives you an easy way. Here is one example:
:START
REM...This is being typed by an endless loop.
GOTO START
When executed, this file will continue to print the endless loop line and the GOTO
command until you tap Control-Break.
Use this subcommand to transfer control in your batch files.
If you want to terminate any batch file before it is complete, issue the break command
[Control-Break].

Interim Review

You have now seen the simple stuff...Let's see how much of it stuck. Following are a few
true/false questions. Think of the answer then look below to see if you were right.


Questions:

1. The file AUTOEXEC.BAT must be in the root directory of the boot disk.

2. Batch files can execute a variety of subcommands in addition to the standard DOS commands.

3. Parameters are designated as %0 through %9.

4. When DOS finds a batch subcommand that is improperly phrased, it stops execution of the file
and shows Syntax error.

5. You may interrupt a batch command by pressing Control-Home.

6. When you type Control-Break to stop a batch file, DOS will ask you if you want to terminate. If
you say No the current command will be ignored but the rest will be processed.

7. The batch filename is substituted for marker %0.8. REMark subcommands display a message
regardless of the the condition of ECHO.

9. PAUSE causes the batch file to temporarily stop and wait for you to press a key.


Answers:

1. True, AUTOEXEC.BAT executes automatically when DOS boots so it must be in the root. (A
trick question as it assumes knowledge from prior tutorials. )

2. True, you've seen some, with more to come.

3. False, those are markers. A parameter is information you type in on the command line that is
substituted for a marker when commands are executed.

4. True, we didn't talk about that specifically, but that's what happens.

5. False, the correct command is Control-Break.

6. True, revealing another little quirk of batch file processing.

7. True, but there is a command you can use to change that as we'll see later.

8. False, REM only shows its message if ECHO is ON. If ECHO is OFF, only ECHO puts a
message to the screen.

9. True.

That's enough. You should now understand the batch file subcommands you are likely to
need most often.
Let's move on to the rest of the subcommands that allow you to program within a batch file.
Subcommands in this section are generally used to create batch programs. As such, they are a bit
more complex than the simply ones studied on the last page.

Tuesday, 29 January 2013

ECHO

You have seen one facet of ECHO already: it can send a messageto the screen. More
importantly, it can help clear the clutter on the screen when a batch file executes. Normally, the
batch file commands would show on the screen as if you were typing them. This can get distracting.
If you want to suppress the command echoing type:

ECHO OFF

To restart echoing, type: ECHO ON
When ECHO is off no part of the actual DOS commands in the batch file will show on the
screen. To display a message put it after the ECHO command:
ECHO Message
As you will see, the REMark command also displays messages; butNOT if ECHO is off!
Use ECHO if you want the message to show no mater what.

REMark

REMark can be used to send messages to the screen or simply to document some part of
your batch file's operation.
Use them extensively in long batch files. The computer operator (it won't always be you)
wants to know what is happening and, over time, you might forget whata complicated set of
commands really does.
The format is:
REMMessage
REMarks can be up to 123 characters long, although you usually won't want to go over the
screen width so you can control the display.
An undocumented, variation of this command is the period. In DOS 2.x, if a line in a batch
file starts with one or more periods (.) it is treated as a  remark. It is dangerous to use this however
since in DOS 3.x and later that same line would be treated as the path to a command!

PAUSE

The last "simple" command is  PAUSE. Its basic function is to stop the execution of the
batch file until you press a key. This can allow you to perform anecessary task; like perhaps
changing a disk or verifying that a particular disk configuration is in place in order to avoid errors
as the remaining parts of the batch file are executed.
In early DOS versions PAUSE would optionally display a message. It does not now. In
order to display a message you have to couple PAUSE with the ECHO command. The format in use
now would require:
ECHO Message
PAUSE
The message will show, followed by the DOS message:
Strike a key when ready... (in early DOS versions)
Press any key to continue... (in later DOS versions)

Saturday, 19 January 2013

BATCH FILES

A batch file is nothing more than a collection of DOS commands placed into an ASCII text
file. When DOS executes a batch file, each line in the file is treated as a DOS command and is
executed as if you had typed the command at the system prompt. Their main use is to automate
DOS command sequences you repeat often or are hard to remember.
Each line in the file is treated as a DOS command and is executed as if you had typed the
command at the system prompt.
In addition to standard DOS commands, batch files also have their own subset of commands
which allow you to actually write a batch file as a small program. Branching and iteration are
allowed in these programs.
Also, batch commands may have external parameters passed to them at the time you execute
the file.
A batch file must have the extension .BAT and you execute the commands in it like any
other DOS command: by typing the file's root name, without the extension, at the system prompt.
Parameters are extra pieces of information that you type after many of the DOS commands. For
example, "DIR B: /W" contains the parameters B: and /W. These modify the basic operation of the
command, but are not required by the command.
You pass parameters to a batch file in the same manner; by typing the information after the
batch command, but before tapping the Enter key. 


The parameters may be used in any place in the batch file  where a parameter would
normally be used as part of the DOS command being run.
Markers are used within the batch file to signify which parameter goes where. Markers are
comprised of a percent sign (%) and a single digit between 0 and 9 (that's ten markers in use at any
one time; remember, zero is a number).
As an example:

Assume that a batch file named REPEAT.BAT is on the current drive. This file contains two
commands: "ECHO OFF" which stops DOS from showing commands and  "ECHO %1 %3" where
the ECHO command can show messages on the screen. If, at the DOS prompt you typed "REPEAT
Red Blue Green" your screen would show "Red Green" as shown in the screen capture: 




In this simple example, three parameters were passed to  the batch file and were placed into
the ECHO command in the order received. Only the first and third are shown as only those were
referenced in the batch file.
The parameters and markers were related as follows...
•  %1 is marker 1 and, in this example, represents "Red", the first parameter;
•  %3 is marker 3 and, in this example, represents "Green", the third parameter;
•  %2 would be marker 2 but, in this example, is not present so "Blue", the second parameter,
is ignored.
Note: Marker zero is assigned the name of the batch file in the form you typed it in (i.e., all caps, all
lower case, or a mixture).
In addition to the normal DOS commands, batch files have their own sub command structure.
Following are the sub commands in the order we will discuss them:
•  ECHO:Turns command display on/off or may display a message.
•  REM:Displays a message on the screen.
•  PAUSE:Temporarily stops the batch file execution.
•  GOTO:Jumps to a labeled set of commands in the batch file.
•  IF:Permits conditional operation of any command.
•  SHIFT:Reassigns the relationship of parameters to markers.
•  FOR..IN..DO:Allows iteration subject to defined conditions.
•  CALL:Runs another batch file then returns to first.
•  @:Turns display off for single command

Subdirectory Review

Assume the shown subdirectory structure...



The following series of commands perform the indicated functions.  Study them and make
certain you understand them.
From the root:
•  MD \WORDPROC\LETTERS\HOME Makes a new directory called HOME in LETTERS.
•  RD \WORDPROC\BOOK Removes BOOK from WORDPROC.
•  CD \WORDPROC\MEMOS Makes MEMOS the active directory.
To move from the root to the subdirectory MEMOS type:
•  CD \WORDPROC\MEMOS
Remember, to make any directory the current directory, simplyissue the CD command using
the pathname that you would use to access any file in that subdirectory. CD \ alone will move you
back to the root from anywhere.
From the root, the following command removes the subdirectory LETTERS:
•  RD \WORDPROC\LETTERS
Remember, before you can remove a subdirectory, it must be empty (all files deleted and other
subdirectories removed), you cannot be in it, and you cannot remove the root directory. In DOS 6.0
you can do both with the single command DELTREE. 




A final reminder:
Use subdirectories as needed, but don't overdo it. Pathnames are limited to 63 characters;
and, you can get lost in the directory structure if you create a  very complex one.  PROMPT$P$G
will help you keep track.
Also, directories are not free. Each takes up some disk spaceso if you fill your disk with
directories, there won't be room for anything else.

Tuesday, 8 January 2013

Make and Remove Subdirectories


If you are going to have sub directories, there must be a way  to make them. The syntax for
the make directory command is:
MDd:pathname\DIRNAME
You can make a subdirectory IN any directory FROM any directory so long as you give the
appropriate pathname. Usually, you will change to the directory you want the sub directory to be in

and then issue a simple MD DIR NAME command. That way there isno mistake about what will
happen.

When you no longer need a directory you may remove it from the disk. The first thing you
have to do is empty it of files and move out of it. Only then will  you be able to remove it. The
syntax for removing is:
RDd:pathname\DIRNAME
You cannot remove the root directory (it's the master for the disk and when it's the only
directory you would have to be in it, and you can't remove a directory you are in).
Note:In DOS 6.0 the command  DELTREEwas introduced. DELTREE will both remove files
from a directory and remove that directory with a single command.


Mysterious Dots

When you are in a subdirectory and issue the DIR command, you willsee something like
this:



The dots indicate you are in a subdirectory. The single dot is the  current directory and the
double dots are the parent to the current directory. Thus you could  move to the parent of
TUTORIAL (in the example above) by simply issuing the command CD ..
Used with care, the dots can speed up subdirectory commands.


Tree

All directory paths and their relationships are called a tree. If you don't remember the
various subdirectories (and optionally the files in them) DOS offers you a chance to see them with
the TREE command:
TREEd:/f

This command lists all paths from the root on the disk. If you use the/f option, you will also
see all files in each sub directory. (Only the file names are shown, not their size or creation
date/time.)
For a permanent record, press Control-PrtScr before issuing  the TREE command and again after.
Your printer will record all text scrolling past on the screen. (Or redirect to a file with TREE d:/f >
Filename.)

[Note: TREE has been removed under Windows.]

Subdirectory Introduction

As the name implies, a pathname is nothing more than a "path" that directs DOS to your
particular file.
You see, with DOS 2.x, IBM/Microsoft introduced multiple directories on a single disk. In
effect, this lets you sort your files into groups and place each related group into its own directory.
This means you don't have to search an entire disk to find one file.
A lower-level directory is called a subdirectory (what else?)
Seriously, consider a disk. To this point you have learned that each file on that disk is represented as
an entry in the directory, put there so both you and DOS can find the file on disk.
If, instead of data, you created a file that pointed to other  files on the disk, you will have
built what amounts to a subdirectory.
DOS manipulates files in subdirectories through several directory commands and what is
called a pathname.
In this section we'll look at the DOS commands for manipulating subdirectories and how we
can set an environment variable (PATH) to allow DOS to find programs.
The DOS directory structure can be thought of as a tree, with the master disk directory being
called the  rootand subdirectories thought of as branches. The root is the hard disk's master
directory. It may contain up to 512 entries. Subdirectories may contain any number of entries (until  the disk is full). A floppy root directory may contain 112 or 224 entries. A typical tree might look
like...



In the example there are five files and two subdirectories in the root. Each of the
subdirectories has similar contents. SubDir1, for example, has three files and one subdirectory in it.
This structure can be extended until the disk is completely full, subject only to the constraint of 63
characters for the pathname that you will use to find a particular file.
The rules for a subdirectory name are just like that for filenames (eight characters followed
by a period and three character extension).
They show up in a directory listing with the designator <DIR> behind them.
Let's see now how to build a pathname.



Pathnames 


Assume the subdirectory structure (only directories are shown, not files)...



This series of subdirectories was set up to categorize  various files developed by a word
processor. Let's move in the structure:
•  \WORDPROC\LETTERS Would be the pathname from the root to subdirectory LETTERS.
•  \WORDPROC Is the pathname from root to WORDPROC.
Note that each subdirectory in the path is separated by a backslash (\). The single backslash at
the beginning of the pathname indicates the root. All pathnames must originate in either the current
directory or root.
A test -- What is the pathname from the root to the subdirectories listed below?
•  Subdirectory LETTERS
•  Subdirectory BOOK
•  Subdirectory WORDPROC
Answers...
•  \WORDPROC\LETTERS
•  \WORDPROC\BOOK
•  \WORDPROC
When DOS is booted, the root directory is automatically selected. To type a file named
MYMEMO.TXT in subdirectory MEMOS the command would be:
C:\> TYPE \WORDPROC\MEMOS\MYMEMO.TXT
\WORDPROC\MEMOS\ is the pathname that DOS would use to find the file MYMEMO.TXT and
then show it on the screen.
If you've got work to do with files in the MEMOS subdirectory, typing the complete
pathname all the time would be inefficient. Therefore, DOS gives you a method of making DOS
recognize the MEMOS directory as the default: the Change Directorycommand.
To change to the MEMOS subdirectory from the root the command would be:
C:\> CD\WORDPROC\MEMOS
If set properly (see just below) the prompt might also change to reflect the change directory
(C:\WORDPROC\MEMOS>, and a DIR command would now show the contents  of the MEMOS
subdirectory instead of the root and DOS would look for all command files in that subdirectory
instead of the root.
An easy way to keep track of where you are in the directory tree is to use the  PROMPT
command to set a prompt that shows the current directory along with the current drive. You can
easily do this by adding the line:
PROMPT $P$G
to your AUTOEXEC.BAT file.

Saturday, 5 January 2013

XCOPY

For copying multiple files the XCOPY command can be a powerful ally. As its name
implies, the command performs extended copies.
Its format (with only often-used options) is shown here:
XCOPYd1:PATH1 d2:path2 /a /m /s /v
Like the COPY command, XCOPY can take a single drive/path designator in which case
files from that destination will be copied into the current directory. Some options:
/A Copy only files with archive bit set; do not reset archive bit.
/M Copy only files with archive bit set; reset archive bit.
/S Copy subdirectories as well unless they are empty.
/V Verify copied files as they are written.
You can copy an entire hard disk to another disk with a single command:
XCOPY C: D: /S
The contents of drive C: will be copied to drive D: a file at  a time, with the subdirectory
structure intact.
You can use the same technique to back up a hard disk to a removabledisk (e.g., Bernoulli
or other removable media - don't use floppies). Note the /M optionabove. When DOS writes a file
to the disk it sets an archive bit in the disk directory to indicate the file has been somehow changed
(it's possible to write a file and not change it but DOS just assumes changes were made). The /M
option for XCOPY can take advantage of this.
To proceed:
1) Make a full backup first.
Use the ~ATTRIB~ command to set all archive bits to ON:
C:\>ATTRIB +A *.* /S
Use XCOPY to copy all files and directories, turning all archive bits OFF in the process (assumes
removable media is G:):
C:\>XCOPY C:\ G: /M /S

2) On a regular basis use the XCOPY command to perform an incremental backup:

C:\>XCOPY C:\ G: /M /S

The backup on drive G: will be an image of the file and directory structure on drive C:. The
incremental backup makes certain the image is current.
Periodically, in order to purge deleted files from the backup  you should start over at #1
above and a clean backup disk. 


Typing a File

Any text file saved in ASCII character format can be easily seen on your video display. Use
the type command:
TYPE d:FILE NAME.ext
All characters in the file will be displayed on the screen, including any control characters,
sometimes resulting in interesting displays.
Any control-I characters found will be interpreted as a tab, and spaces will be added to get
the cursor over to the next 8-character boundary; some output may appear as tables. Control-Z will
cause output to stop.
Attempting to TYPE a .COM or .EXE file will result in garbage on the screen, and should
generally be avoided.

Copying Files

The COPY command is a very powerful command within DOS. With it you can create
duplicates of individual files, join several files into one, and even use your computer like a simple
typewriter by "copying" from the device named CON: to the device named PRN (inefficient, but
OK for short notes).
Copying one file to another (copies from filename1 to filename2):
COPYd1:FILENAME1.ext d2:filename2.ext/v
/v option verifies the copy as it takes place. This adds confidence at the price of slower operation.
There are other options not shown here. Wildcards are allowed.
For example,
C:\>COPY ADDRS.LST B: Copies the single file ADDRS.LST from C: to B:.
C:\>COPY *.* B:/VCopies all files on C: to the disk in B: and verifies the information is it is being
written.
C:\>COPY ADDRS.LST Yields an error message. Can't copy a file to itself.
C:\>COPY B:*.*Copies all files from drive B: to drive C:. (If a destination is not specified, the
default drive and directory is used.)
Copy can also be used to concatenate (join) several files by using the following form:
COPYd1:FILENAME1.ext+d2:FILENAME2.ext+... d0:filename0.ext/v
The options are the same as the previous version of the copy command.
All specified file names (#1, #2, etc.) will be copied and joined into filename0. If no filename0 is
specified, the first source file named will be used.
Wildcards are dangerous with this command. 

Example:
Contents of FILE1:This is file number one
Contents of FILE2:This is file number two
C:\>COPY FILE1+FILE2 FILE3
Contents of FILE3: This is file number one This is file number two
The COPY command can be used to create text files by copying from device CON: to a file.
The procedure is outlined in the text of the example below.
C:\>COPY CON: TEXT FILE
This is the text to go into the text file being created. Each line is typed to the screen and it is
being saved into a buffer for later transfer to the file TEXT FILE. Each line may be corrected as it is
typed, but cannot be changed after it is terminated by the carriage return. Also, if you happen to
type beyond column 80 on the screen, you cannot correct anything on the line above. Each line
must be terminated by a carriage return (the enter key). You  signal you are finished by typing a
Control-Z, the symbol for end-of-file, followed by Return. ^Z
1 File(s) copied

Checking the Disk

Now and again it is useful to check the integrity of the disk directory and file allocation
table (FAT). The FAT is so important to the disk that there are two copies of it on each disk.
The CHKDSK program does this for you. The basic format is:
CHKDSK d: file name.ext /f /v
Using the file name causes it to be checked for continuity (i.e.,  being stored on contiguous
sectors on the disk for more efficient access).
•  /f tells DOS to automatically fix the FAT and other problems
•  /v is a verbose mode that shows progress as disk checking is taking place
Example:



Only use the version of CHKDSK that came with your version of of DOS. Crossing versions can
cause great damage to a disk.


Backing Up a Floppy Disk

Floppy disks wear out after several hundred spin hours. Well before  then you should have
made a copy of the disk to preserve the integrity of its contents. You can, of course FORMAT and
then COPY*.* to accomplish this. There is a quicker way however:
DISKCOPYd1: d2:
If you do not give drive specifications, the utility will ask for them.
All information on the target disk will be destroyed, and DISK COPY will format the target
if it is found blank. Be careful, it's easy to destroy data by putting the disks in backwards!


Problem : Copy disk A: to B:. Issue the proper command.
Answer
: C:\>DISKCOPY A: B: 



Erasing Files

Files you no longer need should be deleted from your disk to make room for more current
files. Use the ERASE (DEL etc) command for this:
ERASE d:FILE NAME.ext
or
DEL d:FILE NAME.ext
Be careful, typographic errors in this command can bring disaster!
You are allowed to delete all files on a disk with the wildcard *  (ERASE *.*), but DOS will
question you.
Recovery BEFORE writing anything else to disk is possible. An UN DELETE utility started
shipping with DOS 5.0. Before that commercial utilities were available.



Renaming Files 

For whatever reason, you may need to change the name of a file on your disk. (Usually this
is the case when you want to change a backup file to another name  in order to return it to active
status.)
Use this format:
REN d:OLD NAME.ext NEW NAME.ext
Wildcards are allowed, but can cause trouble if you are not careful.
The rename command will give you an error message if NEW NAME exists.

Friday, 4 January 2013

Command Syntax

Each DOS command has a mandatory part and some have an optional part. Presented here,
the mandatory parts will be shown in  bold CAPITAL LETTERS and the optional parts in lower
case.
For example,

DIR d:pathname\filename.ext /p /w
is the complete command for a disk directory. Note that only DIR is necessary.
You may note the term path name in the above command. The path name is the full
descriptive name to any location on the disk. It includes the names of all directories (see
sub directories later in this section).
In some commands you may use wildcards. A wildcard, like the joker in a card deck, can
stand for any character or group of characters.
The ? represents any single character:
FILE? = FILE1 or FILED etc.
The * represents any group of characters:
*.* = Any file and extension
Use caution with wildcards. They can be dangerous with commands that do things like erase
files. Also, in some cases a wildcard formulation can be misleading. The combination
AP*EX.COM does not mean all files that start with AP and end with EX in their root name and
with a COM extension. It means all files starting with AP  and having an extension of COM. The
EX is meaningless as it is ignored because of the asterisk.

Disk Directory

To see a listing of what is on a disk, issue the DIRectory command.
It comes with several options (shown are the most useful, not all).
DIR d:filename.ext /p /w
DIR alone will show the complete directory. With the optional file name, DIR will try to find
just that file.
•  The /p option causes a pause when the screen fills.
•  The /w option yields a full 80-column display of just the file names.
There are other options for sorting the listing and displaying the contents of lower-level directories.
Now we'll see what would happen when you type DIR at the prompt.


Note several things here.

•  DIR tells you what files are on the disk, how big they are, and when they were created.
•  DIR also tells how many files total are in the list, how much space those take and what free
space remains.

Three Simple Commands

CLS Clears the screen and puts the cursor in the home (upper left) position.
VER Shows the DOS version number on the video display. You are shown the one-digit version
and two-digit revision:
MS-DOS Version 6.00
VOL d: Displays a volume label, if one exists. The label is a name you have given to the disk when
it was formatted. It is used for identification purposes. (The serial number is put on the disk by the
FORMAT utility.)
Volume in drive C is HANDBOOK
Volume Serial Number is 2C35-16F9


Date and Time
 

These two commands show and/or set the system date and time.
Early computers relied on you to set the DOS clock during the boot process. In short order
peripheral makers came out with clock cards that, with the helpof a battery, kept a clock going and,
with the help of a program in AUTOEXEC.BAT, loaded the time into DOS for you during boot.
New computers have the clock built-in and do not require a program to load the time.
If your clock battery fails, the default values will be 1-1-80 for the date and 00:00:00.00 for
time. Now and again you will see files with a create date  of 1/1/80; they were created on a system
where the clock has failed and DOS has used its default value.
For the DATE command you can enter the date as month/day/year with hyphens or slashes,
i.e., 3/1/94 or 3-1-94 are acceptable dates.
Do not enter the day of the week, even though it shows on the screen. The computer will
calculate it for you. A two digit year assumes dates between 1980 and 1999. In 2000 you will have
to start putting in all four digits. 


The format for DATE is:

DATE <date>
On early computers the time setting required a 24-hour clock, i.e., any time after noon had to
have 12 added to it, for example 3:00 pm had to be entered as 15:00. While the TIME command
will still respond to this type of time, you may not also enter  3:00p and the computer is smart
enough to know you mean 15:00.
The format for TIME is:

TIME <time>
On most computers these commands will change the permanent clock settings as well as
changing the date/time in DOS.
Disks straight out of the package need to be formatted, that is have tracks and sectors defined so
DOS can find programs and data on the disk.
The command syntax is below (only the most useful options are shown).
FORMAT d: /s /u
where
•  d: defines the disk that will be formatted
•  /s puts the DOS system on disk to make it bootable
•  /u specifies an unconditional format (can't unformat the disk)
An example:

Problem :Format the disk in drive A: without UNFORMAT information.
Answer :The proper command is:
C>FORMAT A: /U 



In order, you are asked to confirm a disk is present for formatting, then told to what capacity
the disk will be formatted (press Control-C to stop the format if this is not correct), then you are
given a report on format progress. At the end you are asked for a volume label (optional) and then
given a report on the success of the format in terms of the number of bytes on the disk. A serial
number is assigned by DOS. It is based on system time and will likely never be the same on two
individual disks. 



Additional Comments
Some microcomputers have 1.2 megabyte 5.25" disk drives. There is the temptation to use
360 kilobyte disks in those drives; don't do it. The track width is smaller and if you then put the
360K disks into a 360K drive, they may not work properly. Likewise, you cannot use the high
density floppy disks themselves in 360K drives. The magnetic properties of the disk are such that
the 360K drives won't format them.
With the introduction of 3.5" drives, higher versions of DOS are required to correctly
support the new formats. The 3.5" drives come in two sizes: 720K and 1.4MB.
Unlike the 1.2MB/360K drives disks, it is possible to format to 720K in a 1.4MB 3.5" drive.
All you have to do is tell the FORMAT command the track/sector combination you need:
FORMATA: /F:720 (this tells DOS to format the disk in drive A: to 720K)
Not all versions of DOS support higher capacity disks. For example, DOS 3.2 introduced
support for 3.5-inch disks, but only at 720K format. In order to format  a 3.5-inch disk at 1.44MB
you will need DOS 3.3 or later.

Input/Output System


This most primitive of the DOS systems has two parts:

•  BIOS (Basic Input/Output System).These are the fundamental routines that control the
keyboard, video display and other peripherals. The BIOS is comprised of a ROM on the
computer's main circuit board and the file IBMBIO.COM (or IO.SYS), one of the two
hidden files on your disk.
•  Operating System.This is the main file-handling system for the computer. Actually, two
systems exist: one for disk-based files and one for non-disk peripheral devices. They are in
hidden file IBMDOS.COM (or MSDOS.SYS). (IBMBIO and IBMDOS areIBM names;
MS-DOS uses IO.SYS and MSDOS.SYS.)
The two systems are necessary because non-disk peripherals demand their data as strings of
characters, while disks move information in large groups, known as blocks.

Command Processor

The command processor (COMMAND.COM on your disk) performs three tasks:

•  It handles critical interrupts...that is, COMMAND.COM takes care of all demands for
attention by parts of the computer. The user typing the Control-Break program break
command is an example of an interrupt.
•  It handles critical errors...that is, COMMAND.COM takes care of problems. For example,
if you leave the disk drive door open during a disk operation COMMAND.COM is
responsible for the error message you will see.
•  It performs end-of-program housekeeping...that is, COMMAND.COM takes care of
making the computer's memory available for other programs and reloading parts of itself if
the program wrote over them.
COMMAND.COM also places the C> prompt on the screen and interprets any command(s) you
might type. In short, the command processor tells the rest of DOS what to do.
Everything that DOS interacts with has a name and the names have  certain rules that have to be
followed. Let's look at some of them.

Default Drive

The default drive is the first disk drive on which DOS will look fora program if no drive
specification is given with the file name.
How do you know what it is? Look at the prompt. The default drive letter is part of the
prompt (unless someone has changed the prompt to eliminate it).
A:\> indicates that drive A (the left or top drive in a two-drive system) is the default drive. The right
(or second) drive in such a system is called drive B and the first hard disk in any system is given the
letter C as its drive designation.
DOS supports many more than drives A through C. In fact, if your computer has them you
can specify up to 63 drive names. (This is a "Catch 22" situation. DOS can respond to 63
drive names but converts all lower case to upper case automatically so you really can't
access 63 devices.) You change drives by typing the desired default  drive followed by a
colon at the prompt. To change to drive C type C: as shown here:


Device Names

Character oriented devices can be addressed by DOS through their names:
•  CON:The name for the video display and keyboard.
•  AUX: or COM1:This is the first asynchronous communications port which usually has a
modem or other serial device connected to it. The second communications port is COM2:
•  PRN or LPT1:The first parallel printer port. PRN comes from printer  and LPT is an old
designator derived from line printer. A colon on PRN and all device names is optional in
later DOS versions. The second parallel port is LPT2:
•  CAS1:A holdover; this is the cassette recorder port.
•  NUL:This is a test device. Anything sent to device NUL: goes into the bit bucket (i.e., gets
thrown away).
Rules for File names
Like devices, disk files have to be identified so DOS can address them. These file names
have specific rules.
The basic form of a file name is:
File name.ext
The first part of the name to the left of the period is called the root name. The root name can
be from one to eight characters long and cannot be the same as a device name. The second part to
the right of the period is the extension. It is optional and, if used, can be one to three characters
long.
The period is used between the root name and extension and must be present if there is an
extension.
The following are legal and illegal characters in a file name:
•  Legal:A-Z 0-9 $#&@!()-{}'`_~
•  Illegal:|<>\^+=?/[]";,* plus control characters and the space
Some other operating systems allow longer file names and there are commercial utilities which
link a database of long names to your short names so you can find files by using more fully
descriptive names.
[Note: Windows allows longer file names with the space but underneath the facade the 8.3 format is
maintained.]
DOS commands are issued at the prompt C:\>. Whatever you type after that prompt that is
not in the COMMAND.COM standard library is assumed to be the name of a file on the default
disk and DOS will search for it under one of three names (in the order listed).
If you type C\:> FILE NAME
DOS will look for: FILE NAME.COM or FILE NAME.EXE or FILE NAME.BAT
The first is a command file (note the COM extension). The second is an execution file (EXE
extension). And, the third is a batch file (a series of DOS commands in a text file which you'll learn
about later in this tutorial). The first file found will be read into memory and the command
processor will start the program running.
Both .COM and .EXE files execute as programs. The difference between the two relates to
how memory is allocated and certain parameters in the computer are set.

Examples of Disk Operating Systems that were the OS itself

•  The DOS/360initial/simple operating system for the IBM System/360family of mainframe
computers (it later became DOS/VSE, and was eventually just called VSE).

•  The  DOS operating system for DEC PDP-11 minicomputers (this OS and the computers it
ran on were nearly obsolete by the time PCs became common, with various descendants and other
replacements).

•  DOSfor the IBM PC compatible platform
The best known family of operating systems named "DOS" is  that running on IBM PCs type
hardware using the Intel CPUs or their compatible cousins from  other makers. Any DOS in this
family is usually just referred to as  DOS. The original was licensed to IBM by Microsoft, and
marketed by them as  "PC-DOS". When Microsoft licenced it to other hardware manufacturers, it
was called  MS-DOS. Digital Research produced a compatible variant known as  "DR-DOS", which
was eventually taken over (after a buyout of Digital Research) by Novell. This became "Open DOS"
for a while after the relevant division of Novell was sold to Caldera International, now called SCO.
There is also a free version named "Free DOS".
DOS consists of an input/output system, a command processor and several utilities. The
utilities are individual program files found on your DOS disk. While part ofDOS, these files are not
needed often enough to make it necessary or practical to keep them in the computer's RAM all the
time. FORMAT.COM, the program that formats blank disks, is an  example of a DOS utility.
Sometimes these utilities are called external commands (as  opposed to internal commands which are included as part of the file COMMAND.COM and remain resident in memory at all times; e.g.,
DIR and COPY).
The command processor is also a file you see on the disk, but once read into the computer's
memory, it usually resides there. Some programs provide their own command processor, and there
are times when the command processor will be overwritten in memory by a program and have to be
reloaded when the program stops executing.
The input/output system consists of two files and a ROM (Read Only Memory) chip. While the two
files are on your disks and are loaded into memory when the computer starts, they are normally
hidden from your view and not available to you for changing.

Thursday, 3 January 2013

Examples of disk operating systems that were extensions to the OS

•  The  DOS operating system for the Apple Computer's Apple II family of computers. This
was the primary operating system for this family from 1979 with the introduction of the floppy disk
drive until 1983 with the introduction of  Pro DOS; many people continued using it long after that
date. Usually it was called Apple DOS to distinguish it from MS-DOS.
•  Commodore DOS, which was used by 8-bit Commodore computers. Unlike most other
DOS systems, it was integrated into the disk drives, not loaded into the computer's own memory.
•  Atari DOS, which was used by the Atari 8-bit family of computers. The Atari OS only
offered low-level disk-access, so an extra layer called DOS was booted off of a floppy that offered
higher level functions such as filesystems.
•  MSX-DOS, for the MSX computer standard. Initial version, released in 1984, was  nothing
but MS-DOS 1.0 ported to Z80; but in 1988 it evolved to version 2, offering facilities such as
sub directories, memory management and environment strings. The MSX -DOS kernel resided in
ROM (built-in on the disk controller) so basic file access capacity was available even without the
command interpreter, by using BASIC extended commands.
•  Disc Filing System(DFS) This was an optional component for the BBC Micro, offered as a
kit with a disk controller chip, a ROM chip, and a handful of logic  chips, to be installed inside the
computer. See also Advanced Disc Filing System.
•  AMSDOS, for the Amstrad CPC computers.
•  GDOS and G+DOS, for the +D and DISCiPLE disk interfaces for the ZX Spectrum.

History of DOS

In the early days of computers, there were no disk drives; delay lines, punched cards, paper
tape, magnetic tape, magnetic drums, were used instead. And in  the early days of microcomputers,
paper tape or audio cassette tape (see Kansas City standard) or nothing were used instead. In the
latter case, program and data entry was done at front panel  switches directly into memory or
through a computer terminal / keyboard, sometimes controlled by a ROM BASIC interpreter; when
power was turned off after running the program, the information so entered vanished.
Both hard disks and floppy disk drives require software to manage rapid access to block storage of
sequential and other data. When microcomputers rarely had expensive disk drives of any kind, the
necessity to have software to manage such devices (ie, the 'disk's) carried much status. To have one
or the other was a mark of distinction and prestige, and so was having the Disk sort of an Operating
System. As prices for both disk hardware and operating system software decreased, there were
many such microcomputer systems.
Mature versions of the Commodore, SWTPC, Atari and Apple home computer systems all
featured a disk operating system (actually called 'DOS' in  the case of the Commodore 64 (CBM
DOS), Atari 800 (Atari DOS), and Apple II machines (Apple DOS)), as did (at the other end of the
hardware spectrum, and much earlier) IBM's System/360, 370 and (later) 390 series of mainframes
(e.g., DOS/360:  Disk  Operating  System / 360and DOS/VSE:  Disk  Operating  System /  Virtual
Storage Extended). Most home computer DOS'es were stored on a floppy disk always to be booted
at start-up, with the notable exception of Commodore, whose DOS resided on ROM chips in the
disk drives themselves, available at power-on.
In large machines there were other disk operating systems, such as IBM's VM, DEC's RSTS
/ RT-11 / VMS / TOPS-10 / TWENEX, MIT's ITS / CTSS, Control  Data's assorted NOS variants, Harris's Vulcan, Bell Labs' Unix, and so on. In microcomputers, SWTPC's 6800 and 6809 machines
used TSC's FLEX disk operating system, Radio Shack's TRS-80machines used TRS-DOS, their
Color Computer used OS-9, and most of the Intel 8080 based machines from  IMSAI, MITS
(makers of the legendary Altair 8800), Cromemco, North Star, etc used the CP/M-80 disk operating
system. See list of operating systems.
Usually, a disk operating system was loaded from a disk. Only a very few comparable
DOSes were stored elsewhere than floppy disks; among these exceptions were the British BBC
Micro's optional Disc Filing System, DFS, offered as a kit with a disk controller chip, a ROM chip,
and a handful of logic chips, to be installed inside the computer; and Commodore's CBM DOS,
located in a ROM chip in each disk drive.

Disk operating system

Disk Operating System(specifically) and  disk operating system(generically), most often
abbreviated as DOS(not to be confused with the DOS family of disk operating systems for the IBM
PC compatible platform), refer to operating system software used in most computers that provides
the abstraction and management of secondary storage devices and the information on them (e.g.,
file systems for organizing files of all sorts). Such software is referred to as a disk operating system
when the storage devices it manages are made of rotating platters (such as hard disks or floppy
disks).
In the early days of micro computing, memory space was often limited, so the disk operating
system was an extension of the operating system. This component was only loaded if it was needed.
Otherwise, disk-access would be limited to low-level operations such as reading and writing disks
at the sector-level.
In some cases, the  disk operating system component (or even the operating system) was
known as DOS.
Sometimes, a disk operating system can refer to the entire operating system if it is loaded off
a disk and supports the abstraction and management of disk devices. An  example is DOS/360. On
the PC compatible platform, an entire family of operating systems was called DOS.

Laptop computers

A laptop computer or simply laptop (also notebook computer or notebook) is a small
personal computer designed for mobility. Usually all of the peripherals needed to operate the laptop
are built in to a single unit. Most laptops contain batteries to facilitate operation without a readily
available electrical outlet. 


Non IBM-compatible personal computers

Though many personal computers are IBM PC compatible using either Microsoft Windows
or closed and open-source Unix-likes such as Linux, a number of other personal computer types are
also popular.
A leading alternative to the IBM PC is the Apple Macintosh, a  combination of proprietary
hardware and operating system. The Macintosh orignally used the Motorola 68000 series, then
shifted to the IBM and Motorola Power PC processors.
In January 2006, Apple shifted its architecture to the same Intel chip found in IBM
compatibles, allowing their computers to run Apple's own Mac OS X as well as other IBM PC
Compatible Operating Systems.
Further PC and PW (Personal Workstation) types through time:
•  Amiga (previously produced by Commodore, now under license from Amiga Inc.) 

•  Acorn Archimedes & Risc PC
•  Atari ST
•  Be OS Be Box
•  Pegasos
•  NEC PC-9800 (At one time, in Japan)
•  NeXT workstations
•  Sun SPARC station
•  SGI workstations like the SGI Indigo and SGI Onyx
The term "personal computer" is often avoided by advocates of the  above computer systems,
ostensibly because of the association it has to the "PC" in "IBM PC".

Wednesday, 2 January 2013

Main memory

A PC's main memory place (or primary storage) is fast storage space that is directly
accessible by the CPU. It is generally used for storing relatively short-term data needed for software
execution. Main memory is usually much faster than mass storage devices like hard disks or optical
discs, but usually cannot retain data for more than a few fractions of a second without power and is
more expensive. Therefore, it is not generally suitable for long-term or archival data storage. As
with the CPU, most PCs use some form of semiconductor random access memory such as DRAM
or SRAM as their primary storage.



Hard disk drive

The disk drives use a sealed head/disk assembly (HDA) which was  first introduced by
IBM's "Winchester" disk system. The use of a sealed assembly allowed the use of positive air
pressure to drive out particles from the surface of the disk, which improves reliability.
If the mass storage controller provides for expandability, a PC may also be upgraded by the addition
of extra hard disk or optical drives. For example, DVD-ROMs, CD-ROMs, and various optical disc
recorders may all be added by the user to certain PCs. Standard internal storage device interfaces
are ATA, Serial ATA, SCSI, and CF+ Type II in 2005. 


Graphics - Video card 

The graphics card - otherwise called a graphics adapter, video adapter, or video card - processes and
renders the graphics output from the computer to the VDU or computer monitor and is an essential
part of the modern computer. On older and budget models graphics cards tended to be integrated
with the motherboard but, more commonly, they are supplied in PCI, AGP, or PCI Express format.
Graphic cards are also the most glamorized computer component as it is the component which
creates all the visual effects on the computer which is essential for playing games.

Mouse Computing



Operating a mechanical mouse (Fig. 2).
1: Moving the mouse turns the ball.
2: X and Y rollers grip the ball and transfer movement.
3: Optical encoding disks include light holes.
4: Infrared LEDs shine through the disks.
5: Sensors gather light pulses to convert to X and Y velocities.




A  mouse is a handheld pointing device for computers, being a small object fitted with one
or more buttons and shaped to sit naturally under the hand. The underside of the mouse houses a
device that detects the mouse's motion relative to the flat surface on which it moves. The mouse's
2D motion is typically translated into the motion of a pointer on the display.
It is called a mouse primarily because the cord on early models resembled the rodent's tail,
and also because the motion of the pointer on the screen can be mouse-like (Fig. 2).