Copyright © 1997 Stephen P. Borgatti, All Rights Reserved Geneva97 Home Page

Introduction to DOS



Drives and directories. Drives and directories are places where you can put files. Directories are contained within drives, and a drive can have many directories. A drive is denoted by letter followed by a colon, as in "a:" or "c:". Typically (but not always), drive letters are assigned as follows:

a: topmost or leftmost floppy disk drive bay

b: next floppy disk drive bay

c: hard disk

d: second hard disk

f-z: network drive (a drive located on another machine)

Drives are locations where you can be. To go to given drive, type its name at the DOS prompt and press enter, as in:

a:

The drive you are currently "in" is called the current or default drive.

Directories are locations within drives. Directories may themselves be hierarchically nested within each other. The top level directory on any drive is called "the root". All other directories are subdirectories of the root. The root is denoted by the drive letter and colon followed by a backslash ("\"), as in

c:\

Except for the root, all directories have names. These names can be up to 8 letters long. To fully specify a directory, you give both the directory name and the directory it is contained in (its "parent") and the directory its parent is contained in and so on up until you get to the drive. For example, the directory "data" is contained within the directory "ap" which is found in the root directory of drive c:. This is denoted:

c:\ap\data

The directory "ap" is denoted:

c:\ap

Like drives, directories are places you can "be". The directory you are currently "in" is called the current or default directory. To go to a directory (i.e. change the current directory), you give the CD command (change directory) at the dos prompt. For example, to change to directory data, type:

cd \ap\data

Note that you do not put the drive letter when doing a cd. The cd command only works within a drive, so if you wanted to go to a directory called project1 on drive a:, you would have to do it in two steps:

a:

cd \project1

Important! Each drive has its own current directory, so if you change the current directory in drive c: to \ap\data and then move to drive a: and change directory to \project1, when you go back to c:, you will be in \ap\data and if you then switch back to a: you will be in \project1.

To make a new directory, use the MD (make directory) command, as follows:

a:

md \project2



Files. Files are contained in directories. File names consist of up to 8 characters (the filename proper), optionally followed by a dot (".") and up to 3 more letters (the "extension"). Examples:

stuff

stuff.dat

ap.exe

Extensions are typically used to classify the type of file it is. For example, the ".dat" extension probably means its a data file. Some common extensions and their usual meanings:

.exe An executable file (i.e. a program)

.com Also an executable file.

.bat An executable file, in ASCII format that contains DOS commands

.sys A device driver (i.e. something that allows the computer to "talk" to a specific piece of hardware, such a mouse or CD ROM drive)

.dat An ASCII data file

.txt An ASCII file

.drv A device driver

.ini An ASCII file containing basic configuration information for a given program

.wp? A specially formatted wordprocessing file

.db A specially formatted file used by a database program



Listing your files. To see what files you have on a given drive or directory, use the DIR command. If given without any arguments (just dir and press Enter) the command lists all files in the current drive and directory. To see the files on a different directory, either go there first then give the dir command, or give the directory name as an argument, as follows:

dir a: {this lists all files in the current directory of the disk in drive a:}

dir c:\ap\data {list all files in the \ap\data directory of drive c:}

You can also specify portions of filenames that you're interested in, such as "*.dat" to get all data files, or "b*.*" to get all files beginning with the letter "b". For example:

dir c:\ap\b*.dat {list all files beginning with "b" that have extension ".dat"}

dir c:\ap\barn*.#* {list files beginning with "barn" whose extensions begin with "#"}



Copying files. There are two basic types of file-copying situations. One is when you make a duplicate of a file, with a new name, located in the same place as the old file. This happens, for example, when you are going to write a letter that is similar to a previous letter, so you use the first as a template. The other copying situation occurs when you make a duplicate of a file, with the same name, located in a new place. This occurs, for example, when you are backing up your hard disk to guard against disk failure. In both cases, you use the DOS COPY command, but the syntax is a little different. The syntax for the first case is this:

copy oldname newname

For example:

copy franke.let dick.let

This creates a file called dick.let which is an exact duplicate of the file called franke.let.

The syntax for the second case is this:

copy filename location

where location specifies a drive and/or directory, as follows:

copy franke.let a: {copies file franke.let to the a: drive,

creating duplicate file called a:franke.let}

When copying a collection of similarly named files to a new location, you can use wild characters like "*" just like the dir command:

copy *.let a:\letters {copies all files in current directory with ".let" extension to

the \letters directory of the a: drive}



Updating files. Sometimes you have a set of files in a directory of a hard disk, and versions of the same files (with the same names) on a floppy, and you want to copy the latest versions of each file from the hard disk to the floppy. But you don't want to overwrite a newer version of a file with an earlier version. The way to do this is to use the REPLACE command. The syntax is just like Case II of the copy command. The basic syntax is:

replace source destination /u

Here is an example:

replace *.dat a: /u

The "/u" is very important. It means "update" and tells the replace command to only copy those source files which (a) are also found in the destination directory and which (b) are newer than their counterparts in the destination directory.

You can also use replace to copy only those files which do not exist in the destination directory -- that is, only new files. For example:

replace *.dat a: /a

This is interpreted as 'copy to the a: drive all files in the current directory with a ".dat" extension that are not already present in the a: drive.

To maintain an up-to-date back up copy of all files in a given hard disk directory, then, you can use the following paire of replace commands together:

replace c:\india a:\india /u

replace c:\india a:\india /a



Printing an ASCII file. To print a text file, you can always read it into your favorite word processor, and then print from there. Or use the DOS PRINT command. It has the following syntax:

print filename(s)

For example:

print blue.dat green.dat {prints two files, blue.dat and green.dat}

print *.dat {print every file with ".dat" extension}

Important! The very first time you print a file after starting up your computer, you will be asked a question after you give the print command. The question is:

Name of list device [PRN]:

Just press Enter and it will print. From then on, it won't bother to ask.

DOS Exercises



1. Create a ".bat" file that backs up all files in a given directory to a floppy disk and then lists all the files on the back up disk.

a) Type copy con update.bat and press Enter. The cursor will go to a new line, but you will not get a new prompt.

b) Type replace %1 a: /u and press Enter.

c) Type replace %1 a: /a and press Enter.

d) Type dir a: and press Enter.

e) Press ^z (control-z) and press Enter. You will get a message saying "1 file copied." and get your DOS prompt back.

f) Type type update.bat to get a look at the file you just created. If you have a printer, type print update.bat to get a hardcopy of it.

2. Run the update program you just created. Put a blank (formatted) disk in drive a: and choose a directory on your hard disk to back up. Do not go to that directory. Stay in the directory in which you made update.bat.

Now, suppose the directory you want to back up is called c:\dos. Then type:

update c:\dos\co*.*

This should copy all files that begin with the letters "co" in the \dos directory of drive c: to the disk in drive a:.

[geneva97/eop.htm]