CS260 - Handout 1

Some DOS Basics


Introduction

DOS, which stands for disk operating system, is the master control program for IBM and IBM compatible microcomputers. DOS directs the flow of information among the various components of your computer system. Whenever you use a piece of software, DOS lives in the background; although it is working constantly, it usually does so without your realizing it. However, when you prepare a disk for use or start up a particular program, you must deal directly with DOS.


DOS FILENAMES

All the programs and data on a disk are stored in files. To access an existing program or data file, you must know its filename. Moreover, when you save a program or create a data file you must assign it a filename.


DOS filenames consist of two parts. The first part (the core) may contain up to eight characters; the second part (the extension) is optional and may contain up to three characters. If the extension is present, it must be separated from the core by a period. For example, in the file name PROGRAM1.CPP, the core is PROGRAM1 and the extension is CPP. Extensions are often used to identify related files; for example, CPP for C++ files and DAT for data files.

Not all characters may be used in naming a file. In particular, the blank is not allowed in a filename. The characters that you may use are


The letters of the alphabet (DOS does not distinguish between uppercase and lowercase letters).

For example, the following are all valid filenames:


0.CPP, PROGRAM.CPP, PROGRAM


Directories

Directories are used to group related files into easily manageable units, in much the same way that file folders partition a file drawer so that documents can be found more easily.


To access a particular directory, you must tell DOS how to find it, you must give its pathname. A pathname begins with a backslash symbol (\) and is followed by a list of directory names separated by backslashes and culminating in the name of the desired directory. (A directory name has the same form as the core of a filename.) For example, your program files might be located in a directory with path name \MYPROG\PELIGO. In this case, we say that your directory PELIGO is a subdirectory of the directory MYPROG.

When you start a computer equipped with a hard disk, you are placed in its root (main) directory. This directory, which has the path name \, usually contains just special files used by DOS to manage the system. To switch to another directory (when presented with the DOS prompt, "C:\"), use the change directory command: Type CD followed by the pathname of the new directory and press the Enter key. For example, to switch to the directory \MYPROG\PELIGO, type


CD \MYPROG\PELIGO


and press Enter. (If the current drive is not C, you will have to type CD C:\MYPROG\PELIGO.)

All commands you execute (either from the DOS prompt or from within C++) apply by default to the current directory. For example, when saving a file in C++ suppose you give it the name P12. Then a file named P12.CPP will be created in the current directory. If you want to act on a file that is not in the current directory, precede its name by the pathname (or disk designation) of the desired location.


SOME USEFUL DOS COMMANDS

This section describes a few basic tasks that DOS can perform for you. (For other commands, as well as more powerful versions of the ones listed here, consult DOS Help) All the commands given here are invoked at the DOS prompt by typing the command name and then pressing the Enter key.


The DIR Command

This command lists all the files stored on the disk or directory specified. If no drive or directory is specified, DOS gives a listing for the current drive or directory. If the command is terminated with /w, a wide listing (which is useful if there are many files to be displayed) is provided. If the command is terminated with / P, DOS will pause when the screen is full; it won't scroll to the next screen until you press a key. Table 1 supplies some examples of the DIR command.


Examples of the DIR Command

COMMAND /ACTION

DIR Lists all files in the current drive or directory.

DIR A: Lists all files in drive A.

DIR C:\CPP Lists all files in the \CPP directory of drive C.

DIR /W Gives a wide listing of all files in the current drive or directory.

DIR B: / P Lists all files in drive B, pausing when the screen fills up.


The FORMAT Command

Before a disk can be used for the first time, it must be formatted. To format a diskette:


On a hard disk equipped system, first make sure that the DOS prompt begins with C. If it doesn't, type c: and press the Enter key to switch control to the C drive. Then type


FORMAT A:


and press the Enter key. (Be sure to end the command with A:, which specifies that the diskette in drive A is to be formatted.) Now, follow the onscreen instructions.


NOTE: If you format a disk that already contains data or programs, everything on that disk will be erased!


The COPY Command

This command copies the specified file from one disk or directory to another. (The original file is not erased in the process.) If a disk and/or directory is not specified, it is assumed to be the current one. Below are some examples of the COPY command.

Command Action
COPY MYFILE B: Copies the file MYFILE in the current drive or directoryto drive B.
COPY A:PROGl.CPP C: Copies the file PROGl .CPP from drive A to the current directory of drive C.
COPY PROG1.CPP C:\MYDIR Copies the file PROGl.CPP from the current drive or directory to the MYDIR subdirectory of drive C.
COPY *.* B: Copies all files in the current drive or directory to drive B.
COPY \MYDIR\*.* A: Copies all files in the MYDIR subdirectory to drive A.

The ERASE Command

This command erases the specified file from disk. If a disk and/or directory is not specified as the location of the file, it is assumed to be the current one. For example,


ERASE PROG2.CPP

erases the file PROG2.CPP from the current disk or directory and


ERASE C:\MYDIR\EXFILE

erases the file EXFILE from the MYDIR directory of drive C.


DOS Help


DOS provides online help for all command-line commands. To get a listing of all comands and a brief description enter at the command line prompt:


HELP

The following will be displayed (just a portion shown):

APPEND Allows programs to open data files in specified
directories as if they were in the current directory.


ASSIGN Redirects requests for disk operations on one
drive to a different drive.

ATTRIB Displays or changes file attributes.
......

To get a detail description of a particular command (for example, the DIR command) enter:

HELP DIR

The following will be displayed:

displays a list of files and subdirectories in a directory.

DIR [drive:][path][filename] [/P] [/W] [/A[[:]attribs]] [/O[[:]sortord]]

    [/S] [/B] [/L] [/C[H]]


  [drive:][path][filename]   Specifies drive, directory, and files to list.
  /P      Pauses after each full screen of information.
  /W      Uses wide list format.
  /A      Displays files with specified attributes.
  attribs   D  Directories   R  Read-only files         H  Hidden files
            S  System files  A  Files ready to archive  -  Prefix meaning "not"

  /O      Lists by files in sorted order.
  sortord   N  By name (alphabetic)       S  By size (smallest first)
            E  By extension (alphabetic)  D  By date & time (earliest first)
            G  Group directories first    -  Prefix to reverse order
            C  By compression ratio (smallest first)

  /S      Displays files in specified directory and all subdirectories.
  /B      Uses bare format (no heading information or summary).
  /L      Uses lowercase.
  /C[H]   Displays file compression ratio; /CH uses host allocation unit size.


Switches may be preset in the DIRCMD environment variable.  Override
preset switches by prefixing any switch with - (hyphen)--for example, /-W.
To remove the commas from the DIR output, use the NO_SEP environment variable.