Pascal Programming: § 2: DOS Fundamentals

Instructor: M.S. Schmalz


We begin our discussion of DOS with several basic definitions.

2.1. Booting the System and Types of DOS Commands.

In order to run DOS, the computer must be started, which is called booting the system. On most IBM-compatible PCs, the following procedures are used.

There are several types of DOS commands, which are: We discuss each of these commands, as follows.

2.2. DOS Disk Commands.

FORMAT command, and why it is needed: UNFORMAT command:

LABEL command:

VOLUME command: CHKDSK command: DISKCOPY command:

2.3. DOS Directory and File Commands.

In order to store information in a reliable, organized fashion, DOS provides commands that manipulate abstract structures called files and directories.

2.3.1. DOS File Structures.

2.3.2. DOS File Naming Conventions.

DOS uses filenames, which are strings of characters that have the following attributes: There are two types of files whose distinction is of primary interest to programmers:
  • User Files or Visible Files have names that can be seen on the monitor when you execute the DIR command to display the contents of a directory.

  • Hidden Files are not usually listed or accessed by users.

2.3.3. DOS File Commands.

COPY command:
  • It is often useful to make copies of files, for backup purposes. The COPY command helps you do this.

    Usage: COPY old-file new-file , where

      old-file is the file to be copied
      new-file is the new copy of old-file.

    Example: COPY test.txt test.cpy .

    Example: COPY old.dat B:\old.cpy

      will copy the file old.dat from the current drive and directory and will transfer that file to floppy drive B at the root directory (\) as the new file old.cpy .

    Example: COPY A:DR*.* B:\PROJ-1\????????.???

      will copy all files on the current directory of drive A: beginning with the letters DR to drive B:'s directory PROJ-1.

    Observation: COPY CON file

      is an obsolete way to create text files, since anything you type on the keyboard (device called CON for "console") will be redirected by the operating system to reside in the diskfile denoted by file .

    Note: The COPY command cannot be used to copy directories.

XCOPY command:

  • XCOPY functions much like the COPY command, but allows interactive selection of files, which was not found in early versions of MS-DOS.

COMP command:

  • COMP allows you to compare the contents of two files.

    Usage: COMP file-1 file-2

    Output: A list of differences between lines in file-1 and file-2 is displayed on-screen.

RENAME command:

  • RENAME is a destructive form of the COPY command.

    Usage: RENAME old-file new-file , where

      old-file is the file to be renamed
      new-file is the new filename for old-file.

    Function: The preceding command sequence causes two operations to be executed:

      a) old-file is copied to new-file, then
      b) old-file is deleted (removed from disk storage).

DELETE command:

  • It is frequently useful to remove old or unused files from your disk(s), to free up space for new information.

    Usage: DEL file

      deletes a file denoted by file from the current disk drive.

    Note: Use DEL with care! If DEL is used in conjunction with a filename that has wildcards in it, then DOS may (or may not) prompt you whether or not you really want to delete all the files that match that wildcarded filename.

ERASE command is a synonym for the DELETE command.

ATTRIB command:

  • Occasionally, you may want to set file attributes such as READ-ONLY (to protect against deletion).

  • Turbo Pascal duplicates the function of the DOS command ATTRIB more reliably. Thus, we will not deal with ATTRIB in this class.

TYPE command:

  • One often wants to view the contents of a text file, which the TYPE command facilitates.

    Usage: TYPE filename , where

      filename is the name of a text file.

    Note: Don't use this command with non-text files, as it may cause your computer to lock up.

PRINT command:

  • One often wants to print a text file on the printer, which the PRINT command facilitates.

    Usage: PRINT filename

      filename is the name of a text file.

    Note: Don't use this command with non-text files, as it may cause your printer to lock up.

2.3.4. Directory Commands.

CD command:
  • CD changes the current directory.

    Usage: CD dir , where

      dir denotes the directory-path of the directory to be set as current.

    Example: CD A:\PROJECTS\PROJ-1

    Variants: A:, B:, etc. set the current (default) disk drive.

MKDIR command:
  • As you build your directory structures on disk, you will want to add new directories to organize new information.

    Function: MKDIR builds new directories in an existing directory structure.

    Usage: MKDIR dir

      creates a new directory dir that will

        a) exist, if the pathname dir is correct; and
        b) be subordinate to the current directory if dir does not exist prior to the execution of the MKDIR command.

    Example: MKDIR A:\PROJECTS\PROJ-2

      will make the directory PROJ-2 under the directory PROJECTS, if PROJECTS exists as a directory on drive A, under the root directory (\).

    Example: MKDIR PROJ-2

      will make the directory PROJ-2 under the current (default) directory, if PROJ-2 does not already exist under the current directory.

DIR command:
  • One frequently wants to interrogate a directory on disk to see if a certain file exists, or if file contents are up to date. The DIR command and its various options help us to perform this task efficiently.

    Function: DIR displays a list of the files and directories in the current directory or in a directory path that is specified in the command. File size is given in bytes or characters, together with the date and time the file was last modified.

    Usage: DIR [dir-path] , where

      dir-path is the pathname of a directory.

    Options: DIR /W

      is the same as DIR, but shows the filenames and directory names only in a multi-column (Wide) display.

    Options: DIR /P

      is the same as DIR, but but shows the filenames and directory names only in a paginated display that you can scroll through by pressing a key (usually the space bar or Enter key).
TREE command:
  • The TREE command displays a hierarchical file structure starting at the current directory (highest level of the hierarchy).

    Usage: TREE dir-path , where

      the directory path dir-path must exist on disk prior to invocation of TREE.

RMDIR command:
  • RMDIR removes a directory, if it exists on disk.

    Usage: RMDIR dir-path , where

      a) the directory path dir-path must exist prior to invocation of RMDIR; and

      b) all subordinate files and directories of dir-path must be deleted prior to invoking RMDIR.

2.4. DOS System Commands.

On IBM-PC compatible machines, MS-DOS provides several convenient commands that help you monitor or change the state of your computer system.

HELP command:

  • This command is new in later versions of DOS.

    Function: Information pertaining to the computer or to a given command is displayed on the monitor.

    Usage: HELP (or HELP command-name , where

      command-name is the name of a DOS command.

DATE and TIME commands:

    Function: Set the system date and time.

    Usage: Enter the command, then respond to the prompt by entering the date and time as DDMMYYYY or HHMM (24-hour format).

CLS command clears the monitor screen.

VER command displays the version number of the version of DOS you are running.

This concludes our brief summary of how DOS works. We next examine DOS' role in supporting applications programs.

2.5. How DOS and Turbo Pascal Work Together.

DOS and Windows® perform the following principal support functions for applications software such as Turbo Pascal:
  1. Provide low-level support for the graphical user interface and associated window managers, windows, graphics objects, etc.

  2. Support file input/output and directory assignment via one or more widgets that pop up on the screen.

  3. Handle errors and exceptions that arise from the interaction of application software (and associated subordinate tools, windows, etc.) with the operating system. High-level error checking is usually provided by the application software, which customarily monitors errors that are caused by the user.

  4. Provide linkages for computational libraries for special math functions that may be required when computing graphics objects.
For example, when one SAVEs a file that you've programmed using the Turbo Pascal interface, the following high-level actions could occur:
    Step 1. The user enters or selects the filename to be saved using a file selector widget (FSW), and clicks on the SAVE button.

    Step 2a. The FSW requests an I/O operation from the operating system (OS), which acknowledges it has received the request.

    Step 2b. The OS requests an I/O operation from the CPU, which acknowledges it has received the request.

    Step 2c. If the CPU is performing another task (e.g., in a multi-tasking system), then that task is suspended, and the CPU requests an I/O operation from the I/O processor (IOP). The IOP acknowledges that it has received the request, and checks to see if the requested disk drive is available.

    Step 3. If the disk drive is not available, the IOP passes that information through the CPU to the OS, and thence to the applications program. The user waits until the requested resource is available. Otherwise, the IOP seizes control of the disk drive and informs the CPU (and, hence, the OS and applications program) that the requested data transfer can occur.

    Step 4. The applications program passes the data to be saved to the OS, which passes the data to the CPU (and, hence, to the IOP). The IOP writes the data onto the disk at the location pointed to by the File Access Table entry.

    Step 5. If the write-to-disk operation encounters an error or an exception, then that information may be passed up to the application program, and user intervention may be sought. Otherwise, the IOP notifies the CPU, which notifies the OS, which notifies the applications program that the write operation has succeeded. Additionally, the IOP modifies the FAT as required, to reflect changes in the disk or file attributes or structure. If a process was suspended by the CPU to permit the I/O operation to occur, then that process is restarted.

Similar processing sequences occur for requested computational operations, graphics operations (such as line drawing), etc.

By preserving software modularity, system developers can enhance maintenance and reliability. That is, by localizing specific operations to given software modules, it is easier to detect places in the source code where errors occur. Such errors can then be fixed at the given modular level, without having to modify the entire software system.

Additional benefits of modular design are realized in efficient replacement of components. For example, when a given component of the application software that performs a specific task (e.g., line drawing) is to be replaced, then that component (if properly designed) can be replaced by another, more capable software module. We call this process incremental upgrading.


This concludes our overview of DOS and its associated commands.
We next discuss software modularity in greater detail.