CS 46A Lab 1

Basic Windows/DOS Usage

Department of Mathematics and Computer Science
San Jose State University

 

 

Operating Systems and Networks.

As you know, operating systems manage the resources of a computer, such as its internal memory, the disk drives, keyboard, monitor screen, and mouse. The primary things we do with operating systems are (1) manage files on disks; (2) run programs; and (3) communicate with other computers locally or via the internet. We will deal with only items (1) and (2) in this lab.

Operating systems come with two different kinds of user interface: a command-line interface like Unix and DOS, and a graphics user interface or GUI, like the Apple Macintosh. Some operating systems have both kinds of interface available, and Microsoft Windows is one of those, with both a GUI and a DOS-like command line, called a Command prompt or DOS prompt or DOS shell.

Networks, or connections among groups of computers, are also of two varieties. Some are managed cooperatively by each connected computer's operating system (cooperative networking). Others are managed by servers ("master" computers) which communicate with each of the other connected computers' operating systems (client-server networking).

The computers you will be working with will be running Microsoft Windows NT Workstation 4.0. (If you have a home computer with Windows 95, the graphics interface will seem the same, but there will be subtle differences!) Your computer is connected to other computers in the Department by Windows NT Server 4.0, which is a client-server network. The features of Windows we will discuss in this lab represent only the barest minimum of what you will need for this course. You will certainly want to learn more on your own, and if you have never used Windows before, or if you are only familiar with Windows 3.1 or earlier, then a good introductory reference is indispensable. You can find many such books in any bookstore. (Windows 95 for Dummies Quick Reference or Field Guild to Windows 95, for example, are nice summaries, but many other books are also good.)

We describe the GUI first. Later in this lab, we will describe the DOS command prompt.

First steps: The desktop, the mouse, logging on and off.

Your computer should already be turned on, even though the screen may be blank. If the screen is blank, hit any key on the keyboard or move the mouse, and you should see the logon screen. It should instruct you to hit [Ctrl+Alt+Delete] to log on. All three keys must be depressed simultaneously. This is best done by holding down the [Ctrl] and [Alt] keys with the fingers from one hand, and hitting the [Delete] key with the other. This should bring up the Logon Information dialog box (a box with fields in it that you fill in by typing with the keyboard, plus some clickable buttons with options such as OK, Cancel, and Help).

In any dialog box, you can use the mouse to go to a particular field by moving the mouse arrow into the field and clicking the left button once. You can also use the [Tab] key to cycle through all of the fields (and buttons). Instead of the mouse, you can use the [Alt] key to go to a particular field: each field has a name with an underlined letter; simultaneously pressing [Alt]+ this letter will go to that field. While the mouse is easy to use, with a little experience the keyboard shortcuts, such as those we have just described, are often much quicker.

Log on by typing your user name, hitting [Tab], typing your password, and then hitting [Enter] or clicking on the OK button with the left button of your mouse. (You should not need to change the Domain Name field in the logon box.)

You should now be logged on. You should see the desktop, which may or may not contain some icons (small pictures representing programs, services, or resources). We will be interested only in the information along the bottom of your screen. On the left is the Start button. To its right is the task bar (which currently should be empty). On the far right is the time. Click once with the mouse's left button on the Start button (keyboard shortcut: [Ctrl+Esc]). You will see a popup menu, containing icons and names.

  1. List all the names you see beside the icons.
  2. How many of them have a black arrow to their right?
  3. How many of them have three dots to their right?
  4. The black arrow after a menu item indicates an item that represents a submenu. Pointing to this item, or clicking once on it ("selecting it"), will display this menu. Then items on the submenu can be selected by the same process. This process can continue, since a submenu can also have a submenu item (a "sub-submenu"). Selecting from a series of nested submenus is indicated by writing vertical bars to separate the menus: Menu | Submenu | Sub-submenu | etc.

    The three dots after a menu item indicate that it represents a dialog box (remember that the logon box is a dialog box). Selecting this menu item will display the dialog box.

    Menu items that have nothing after them represent programs to run. You must double-click on these with the mouse to run them, or select them and hit [Enter].

    Menu items can be selected from the keyboard by using the arrow keys, or by pressing the underlined letter in their names (if there is one).

    Run the Help program from the StartUp popup menu. Use the mouse to click on the "Index" tab (if it isn't already on top). You will get a dialog box asking you for a topic. Type in "password." Note how the list of topics shown follows your typing. Hit [Enter]. Now you have a subtopic selection menu. Select "Changing your password" and hit [Enter] again.

  5. What does the new Help box say you must do to change your password?
  6. Follow these instructions to change your password. (You don't need to do it now, but later when you feel confident and your lab instructor says it is ok, please go ahead and do so.) It is a good idea to get into the habit of changing your password regularly. Caution: your pasword should be complicated enough so that it can't be easily guessed, but simple enough so that you can remember it without writing it down. Getting your password reset by the technical staff can take time!

    Congratulations! You have already begun to understand the Windows user interface! Make sure that you still have the Help Window with the instructions for changing you password displayed on your screen. This window has some features you will see over and over again in applications. There are three small buttons in the upper right hand corner. Clicking the button with an X closes the window and the application. Clicking the button with the box and bar makes the window as large as possible ("Maximizes" it). Clicking the button with the small solid bar "Minimizes" the window and application: it is reduced to an item on the Task Bar. Clicking it in the Task Bar restores it to the desktop (you can also use [Alt+Tab] to select a minimized process). Try maximizing and minimizing this window now. Then return it to its original state as a small window partially covering the screen.

    There are many other functions associated with a window. Here are just two of them:

    A window can be moved by moving the mouse to the window title bar (the colored bar along the top of the window with the name and buttons in it), holding down the left mouse button, and dragging it around the screen. Try this now. This is one example of a standard mouse operation called drag and drop.

    Associated with each window is a Control Menu that can be displayed by clicking on the icon in the upper left corner (in the case of the Help window that should be still on your screen, this icon has a question mark in it). Try this now. Notice that this menu can also be used to maximize, minimize, and close the window.

  7. What does the Control Menu say is the keyboard shortcut to close the window?
  8. Close the Help window, and select the Shut Down choice on the Start Menu. You should see a dialog box that gives you several choices. Always select the "Close all programs and log on as a different user" option. Do this now. Your computer should return to the screen it showed before you logged on.

    You should always shut down the computer with this option when you leave the lab, even for a short time. If you do not, someone else can use your account.

    Never turn off the power to your computer, unless a lab assistant says you can!

    Disks and Windows Explorer.

    Disks for computers come in two main types, floppy (removable) and hard (non removable). Whether hard or floppy, a computer disk is essentially a round, flat, object coated with a thin layer of magnetic material and (if a floppy) protected by a plastic case.

    A hard disk is usually fixed inside the computer unit and is capable of holding large quantities of information, often a gigabyte (one billion bytes) or more. All computers in the student labs are equipped with at least one 31/2" High Density (1.44 MB) floppy drive and a hard disk.

    Caution: Remember that information is recorded magnetically on computer disk. Be careful to keep floppy disks away from things that generate magnetic fields, like TV sets and security gates.

    In addition to the disk drives that are physically present in a computer, there may be several mapped drives that are provided by the network server. These are not actual drives at all, but look to the operating system (and to you) as though they are.

    The drives that hold the disks are named by a letter followed by a colon (:). The names a: (and perhaps b:) are the floppy drives in the computer unit that sits in front of you. The names c: and d: are usually used to name hard disk drives in that same computer. Higher letters like j:, k:, m:, ... are mapped network drives.

    The drives that you will be interested in are:

    1. The a: drive, where you will insert your own floppy to save your work on.

    2. The j:drive, where space is provided to you by the network for your work. This drive (or the network disk space it represents) is yours for the semester, but it should be backed up regularly to a floppy -- you should never rely on the system to hold your important work (plus you might want to do some work at home sometime!).

    3. The k: drive, where you will find stuff that is distributed for your use in these labs, and where your instructor may also distribute course files.

    There are many ways to find drives and view their contents using Windows. The program we will use is called Windows Explorer.

    Make sure you have a new 3 1/2" floppy of your own available. Logon to your computer. Select Programs | Windows Explorer from the Start menu (keyboard shortcut: [Ctrl+Esc], then p, then [Down Arrow] to Explorer, then [Enter]). You will see a window with two subwindows. The one on the left is titled All folders, the one on the right is titled Contents of ... , with the name of the specific item selected in place of the three dots. Typically, on starting Explorer this is either the hard drive of the machine, or one of the mapped network drives. In the All Folders window, you will see listed all the disk drives that are available, with their drive letters in parentheses after their names. You may have to use the scroll bar (a vertical strip on the right-hand side of a window with a bar in it and an arrow on either end) of the All Folders window to see them all. If there is no scroll bar , then everything is already visible. An alternative to using the scroll bar with the mouse is to use the [Page Up] and [Page Down] keys.

  9. List all the available drives with their names and drive letters.
  10. Note that each drive has a small box next to it with either a + or - sign in it. This indicates whether the folders (or directories) contained on the drive are listed below it or not (+ indicating no, and - yes). This can be "toggled" by clicking once with the mouse on the box. Try this now with drive k:. Then try it for drive a:. You should get an error message, since there is no disk in drive a:.

    Insert you disk into drive a: and click on the + beside the drive again. If you still get an error message, your disk is not yet formatted. Point to drive a: in the left box of Explorer with the mouse and press the right button on the mouse. This should bring up a popup menu called the shortcut menu or context menu.

    Associated with services, devices, and programs (objects in Windows) are shortcut menus that contains commands directly related to the object. This menu can be displayed by clicking on the object's icon with the right mouse button (if the object is a window, then you must click in the title bar).

  11. What are the commands listed in the a: drive shortcut menu?
  12. If your floppy disk was not formatted, do it now using the shortcut menu. (You will almost certainly have a 1.44 meg floppy, so other formatting options can be ignored. In any case, Windows will always select the best option for the hardware you are using.)

  13. Now bring up the Shortcut menu of drive a: again, and click on Properties. What information about the disk is displayed in this window?
  14. This window contains a new feature called Pages. The pages of a window are indicated by "file tabs" at the top of the window, just below the title bar. Clicking on a particular tab brings up the page associated with that tab.

  15. Click on the Tools tab of the Properties page for drive a:. What tools are listed?
  16. This page (and the other page in Properties) contains a Help Shortcut Button on the upper right, next to the Close button. Click on this button. Note the change in the mouse icon. Now click on the Defragment Now... button. What does Help say defragmenting does to a disk?
  17. Now click on the Check Now... button. This will run the ScanDisk utility, which is extremely useful for finding and fixing problems with disks. Run this utility on your floppy in the a: drive. Make sure it found no errors.

    Directories.

    Since disks are capable of holding a lot of information it becomes essential to organize your files (documents or programs) on the disk. As you accumulate files on a disk, you can store them in groups by creating file folders. File folders are also called directories. Many novice users think that there is a difference between a folder and a directory, but that is not true. In the rest of these labs we will call them directories, because this is the term inherited from DOS and Unix. Be aware that "folder" is often used in current documentation. Each directory can contain any number of files and other directories called subdirectories (subfolders). This arrangement is known as a hierarchical or treelike directory structure.

    Formatting a disk creates a single directory, called the root directory. The name of the root directory is simply the drive name followed by a backslash: a:\ , b:\ , j:\ , and k:\.

    To see the contents of the root directory on the k: drive, select it in the left box of Explorer. The contents appear in the right box. You can tell the difference between a directory and a file by looking at the icons next to the names in the right box: a directory has a yellow file folder icon next to its name. All other icons indicate files. The root directory of the k: drive contains only directories.

    To see the contents of the subdirectory named cs46alab, double-click on its icon in the right box, or click the + button next to the k: drive in the left box and then select cs46alab in the left box.

  18. How many files are contained in the directory k:\cs46alab? How many subdirectories does it contain?
  19. To see the contents of the subdirectory named lab2, double-click on its icon in the right box of Explorer.

  20. How many files are contained in the directory k:\cs46alab\lab2? How many subdirectories does it contain?
  21. A path is a sequence of sub-directories separated by '\' (the backslash character). For example,

    k:\cs46alab\lab2

     

    describes the path on the k: drive to the files in the lab2 subdirectory. While the path can be deduced by looking carefully at the directories shown in the left box of Explorer, it is often helpful to have the path explicitly shown in the Contents of ... bar in the right box. If it does not already appear there, you can change the settings in Explorer so that it does.

    To change the view settings you must use the View pulldown menu on the menu bar of Explorer (the bar just under the title bar) by either clicking on View or by using the shortcut key [Alt+v] (note the use of Alt for a menu-bar item, as opposed to just the letter for a pulldown menu item). Now select the Options menu item, and then, on the View page of the Options dialog box, click on the box next to "Display the full path in the title bar" so that a check-mark appears. Then click OK or hit [Return].

    You should now see a path displayed after "Contents of" at the top of the right Explorer window. This is the current directory in Explorer. Every application you run in Windows that deals with files will have such a current directory, with a default value such as c:\ or j:\ on startup. This directory can be set by clicking down the directory path in the directory structure shown in a box similar to the right or left box of Explorer. The left box of Explorer, which displays the subdirectories of those directories whose names are preceded by a - , is also said to display the directory tree.

    There are many different options for the Explorer display. For example, select View | Large Icons ([Alt+v] g).

  22. What changed in the Explorer display?
  23. Reset the Explorer display to View | List. We will now investigate how to create new subdirectories. Switch to the j: drive in Explorer.

  24. How did you do it?
  25. What files do you already have on the j: drive?
  26. To create a new directory in Explorer, select File | New | Folder (the keyboard shortcut is [Alt+f], then w, then f). This should have placed a new folder on the j: drive and given it the temporary name New Folder. It also leaves the cursor in the name field, allowing you to change it immediately. Hitting [Delete] will erase the name, or you can use the arrow keys to position the cursor to change the name. Change the name of this directory to TEMP (use uppercase letters). Then hit [Enter].

  27. What name is shown by Explorer for this directory now?
  28. Now point the mouse to the directory icon for this newly created directory and click the right button to bring up the shortcut menu. What operations are available on this menu?
  29. One of the operations is Rename. Use Rename to rename the directory "Cs46a  Lab" (two words separated by a space, each word with first letter upper case, the others lower case).

  30. What is the name of the directory shown in Explorer now?
  31. Use the Rename command again to rename the directory "Cs46a" (i.e. delete.) What is the name of the directory shown in Explorer now?
  32. A directory name or file name in Windows can have letters, numbers, and some special symbols, including spaces. Both uppercase and lowercase letters are permitted, but Windows will not distinguish two names that differ only in the case of the letters. As you saw, the network file system here at SJSU applies further strange restrictions to directory names. These restrictions are different from what you see at home. Also, applications may have special requirements on file names. If an application you are using does not find a file that seems to be there, you should tell your lab instructor. Many annoying upper/lower case conversion problems can occur in Windows NT.

  33. Create another new directory on the j: drive, and give it the name CS46A (all upper case letters). What error message does Windows give you? What does it do after you click OK?
  34. Files.

    Directories are actually files that contain other files. Eventually of course, we want to create files that contain something besides other files. Every application has its own way of doing this. In this section you will learn how to create simple text files, and to copy, move, and back up such files.

    Hit the [Esc] key and then delete the new directory that you created at the end of the previous section. Then double-click on the cs46a directory you created previously. Now select File | New | Text Document from the Explorer menu.

  35. What is the temporary name given to this new file?
  36. Hit the [Esc] key to accept the temporary file name for now. Then double-click on the file icon.

  37. What is the title shown in the title bar of the new window that appears on your screen?
  38. Type Now is the time! on the keyboard. Then select File | Exit and save the changes. Then right click on the file and select Properties.

  39. What is the size of the file as reported in the properties window? What attributes does it have?
  40. The file you have just created is a text document which is associated with the Notepad application. Windows distinguishes documents based on a file extension consisting of three characters (usually letters), which may or may not be hidden from view in the display.

    Close the Properties window for your text file if you have not already done so. Then select View | Options and make sure the check box next to "Hide file extensions for known file types" is unchecked. (Click on it if it is checked. This should make the check disappear.) Then hit [Enter] or click OK.

    File extensions in Windows, if they are shown, are displayed after a period (.). Directories usually do not have an extension. If an extension is registered, then the file is associated with a particular application. Other file extensions are associated with Windows or DOS directly. Often these files are not even shown in Explorer (they are hidden). A few standard file extensions, some of which you will learn more about later, are:

    imageExtension imageFile Type

    image.sys imageSystem files or device drivers.
    image.exe imageExecutable programs
    image.com imageExecutable DOS programs
    image.txtimageText files
    image.batimageBatch files
    image.bakimageBackup files: These are created when you imageimagesave a file. The previous version of imageimageimagethe file is saved with this extension.
    image.cppimageC++ language source code.
    image.objimageObject code, i.e. machine language code imageimageproduced by compiling a .cpp file.

  41. Select View | Options again. What file types are listed in the "Hide files of these types" box?
  42. Select the File Types page in the Options window. Find the Video Clip file type in the Registered File Type box. What extension do these files have? What application is used to open these files (the "Opens with" attribute)?
  43. Files and directories often need to be copied and backed up to floppies. There are three primary ways to do this in Windows Explorer, each of which is useful under different circumstances:

    1. Individual files or directories can be moved or copied on the screen by using drag-and-drop with the mouse: you select a file or directory with the mouse, hold down the left mouse button, and drag the file icon to a new location to move the file or directory (including all its contents). Holding down the [Ctrl] key before depressing the left mouse button will copy the file/directory instead of moving it. (This is not necessary if you are copying to a different drive -- the Windows default is to copy between drives.) This is a very quick method, but only if both the source file/directory and the destination directory are visible on the screen.

    2. Individual files or directories may also be moved/copied by using the shortcut menu. Two shortcut commands are useful for this: Send To copies quickly to a floppy for backup; Cut and Copy use the Windows Clipboard to move/copy files/directories. The use of Send To should be obvious. Copy places a copy of the file in a central repository called the clipboard. You then select the destination directory in Explorer, right click to display the shortcut menu, and then select Paste. Cut is used similarly for moving files. These methods work best for backing up a single file/directory to a floppy, or in cases where the destination in the directory tree is not immediately visible on the screen.

    3. Finally, the Explorer menu itself can be used to copy/move files and directories. This is the method of preference when you want to select multiple files and/or directories. (Remember, if you want to copy all the files in a directory it is best to copy the directory itself.) You first need to select all the files/directories for copying. You do this by clicking each file you want copied with the mouse while holding down the [Ctrl] key. Then select Edit | Copy or Edit | Cut on the Explorer menu (to copy or move) as in the previous method, or select File | Send To to backup to floppy.

    Backup your j:\cs46a directory to the a: drive using Send To on the directory shortcut menu. Verify that the text file contained in this directory was copied correctly along with the directory itself.

  44. What did you do to verify that the text file was copied correctly?
  45. Remember, even though it is likely that all your data on drive j: will remain there (at least for the duration of the semester), never rely on this! Always back up all your files whenever you use the system! Your instructor will likely not accept "The lab system crashed!" as an excuse for late or missing homework.

    Make a subdirectory of j:\cs46a called lab. Then copy the directory k:\cs46alab\lab2 to j:\cs46a\lab using the Clipboard. Then copy all the files from k:\cs46alab\cccfiles to j:\include (this directory may already be there, but if it isn't, you should create this directory too). HINT: to copy all the files from a directory without copying the directory itself, use the Explorer menu and Edit | Select All.

    You have just set up your j: drive for the next lab! In future lab work this semester you should always use the j:\cs46a\lab directory. For course work in CS46A, you should create other appropriate directories in j:\cs46a (such as programs, etc.). Later on, you will need these subdirectories to keep things straight.

    Wildcards and Find.

    Often when we want to copy files, we only want files of a certain type (that is, with a certain file extension). For example, we may want to copy only source code files (with extension .cpp). We could go through the list in Explorer looking for each file of that type, but this is tedious and error-prone. It is much better to use a Windows utility called Find. This utility also allows us to find a file or files whose name we only partially remember, through the use of wild cards.

    In Explorer, select the directory k:\cs46alab\cccfiles. Then select Tools | Find | Files or Folders. In the Find dialog box, type *.cpp in the Named field (the cursor should already be there when Find starts). Then hit [Enter] or click on Find Now.

  46. How many files did you find?
  47. Find is also available directly in the Start menu, but using it from within Explorer is easier since it automatically sets the directory for the search to the current directory in Explorer.

    The asterisk (*) in the entry *.cpp that you just typed stands for any sequence of characters of any length. (Note how the file extension is given separately.) The other wildcard that is available is ?, which stands for any single character. Here are two more examples of the use of these wildcards:

    The string s*.txt matches all files beginning with the letter s and having the extension txt.

    The string st??.ba? matches all files beginning with the letters st whose filenames have four characters, and whose extensions consist of three characters beginning with ba.

    In the Find window select Edit | Select All (or the keyboard shortcut [Ctrl]+a). Then select Edit | Copy (or [Ctrl]+c). Now switch back to Explorer (click the mouse in the Explorer window or click its button on the Task Bar), select j:\cs46a and then Edit | Paste ([Ctrl]+v).

    This is not actually a place where we want these files. (In fact, they are already in the directory j:\include.) So we would like to cancel the last copy. This is easy in Windows: the last action can always be cancelled by selecting Edit | Undo or [Ctrl]+z. Do this now!

    The DOS command line.

    As useful as the Windows GUI is, sometimes it is easier and faster to use actual typed commands to achieve the same actions. This is particularly true in situations where a standard series of actions need to be performed repetitively (such as in a backup or compile of a group of files). In such cases, the typed commands can be put into a special kind of text file called a batch file and executed as though they were being typed at the keyboard. This powerful automation method will be studied in Lab 6. For now, you will simply learn the standard DOS commands that achieve the same results as the Windows actions from previous sections.

    Warning. The DOS command line is one of the areas where Windows NT 4.0 and Windows 95 differ a lot. If you are using Windows 95 at home, do not expect everything to be the same as it is described here.

    In the Start Menu, select Programs | MS-DOS Prompt. You should see a window in black on your screen with a prompt showing you the current directory (usually C:\WINDOWS), then a "greater than" sign (>), and then a blinking or solid line or rectangle indicating the cursor position.

  48. Display the DOS window shortcut menu. How did you do it? What options does it contain?
  49. There are many formatting options available by selecting Properties in the shortcut menu, but it is easier to use shortcut commands for the most common formatting options. One such shortcut is [Alt+Enter] which switches DOS in and out of full screen mode.

  50. Hit [Alt+Enter] twice. What happened?
  51. Type the command help, followed by [Enter]. Keep hitting [Enter] until you are back at the command prompt. What did you see?
  52. The DOS help utility is a great place to learn how to use DOS commands. Even better is to look up the DOS commands in Windows Help. (After running Help from the Start menu, select the topics commands | Windows NT.) All the commands below are explained in fuller detail in Windows Help, together with examples and notes.

  53. Type j: and hit [Enter] (after this, it will be understood that each command should be followed by [Enter]). What happened?
  54. Type dir. What do you see?
  55. Type cd cs46a\lab. Then type dir. What do you see?
  56. How can you tell which listed file names are themselves directories?
  57. Now type k: and then dir. What do you see?
  58. Now type j: [Enter] and then cd .. (the letters cd followed by a space, followed by two periods). What happened?
  59. You have just learned three basic directory commands in DOS:

    Typing a drive letter such as j: or c: switches DOS to that drive, and changes the current path accordingly. Note that, if you have previously set a path on a particular drive, DOS remembers that path and goes back to it when you switch back to that drive.

    Typing cd plus a path changes the directory (hence the two letters c and d) to the given path. Here (and in most other DOS commands) a path can be relative to the current directory or absolute. Absolute paths always start with the root directory (\) and can include a drive letter followed by a colon. Relative paths begin with a file name in the current directory. There is one special file name that is very useful: the double period (..) refers to the parent directory of the current directory in the directory tree, so that it is possible to go up the tree with relative paths as well as down.

    Typing dir lists files in the current directory. You can also give dir a relative or absolute path, and it will display the appropriate directory. Useful options to this command for large directories are /p and /w (look these up in Help!). Dir can also be used in way similar to Windows Find to locate files (see its listing under the file commands below).

    An option to a DOS command is a forward slash, followed by a letter. (Forward slashes are to be clearly distinguished from backslashes, which are parts of paths.) Most DOS commands have several options, which you can find in Help.

  60. Go back to the j:\cs46a\lab directory. How did you do it?
  61. Type dir and then dir/w. What are the differences?
  62. How can you tell which file names are directories using dir/w?
  63. File names in DOS are restricted to eight characters, while in Windows names can be longer. Thus, DOS must use a convention to shorten Windows names so that they can be accessed in DOS. This convention is to use a tilde (~) and a number (to resolve name conflicts) as the last two characters in the DOS name, if the name is longer than eight characters.

  64. What is the DOS file name of the New Text Document that you created previously in the j:\cs46a directory?
  65. Here are three other useful commands related to directories:

    · md -- Makes a new directory. You type a name after the command, and DOS creates a new directory with that name in the current directory. You can also use a relative or absolute path.

    · tree -- Displays a directory tree on the screen. Can also be used with a path.

    · rd -- Removes a directory. This only works, however, if the directory is empty. If a directory contains lots of files, including subdirectories, you must first use the del command (see below) with the /s option to make the directory empty.

  66. Draw the tree that is displayed by the tree j:\ command.
  67. Here are two additional commands for performing formats and error checks of disks:

    · format -- Formats a floppy. For example, format a: formats a floppy in the a: drive.

    · chkdsk -- Performs error checks similar to ScanDisk (but not as thorough and a little faster).

    Write down the information that is displayed by the chkdsk a: command.

    Here are the essential DOS commands to copy, move, delete, and locate files:

    · copy -- copies a single file or group of files in the same directory. For example, the command

    copy *.cpp a:

     

    copies all files with the extension cpp in the current directory to the most recently set subdirectory of the a: drive.

    · xcopy -- this is similar to copy, except that, if it applied to a directory or group of directories, it can also copy all subdirectories as well, if used with the option /s.

    · del -- deletes a file or group of files from the current directory. This will not delete directories unless you use the /s option.

    · move -- this moves a file or group of files to a new location. If a file being moved is a directory, it implicitly moves all files contained in that directory (including all subdirectories). By only specify a new name, but not a new location, move can be used to rename files and directories.

    · dir -- This command has been explained previously: it lists all files in a selected directory in one of several available formats. Used with wildcards and the /s (subdirectory) option (and possibly also the /p option), it can find and list all files meeting the given criteria contained anywhere in a directory tree. Thus, dir can be used to find the locations and names of files in a way similar to the Windows Find utility.

    · fc -- This is the File Compare utility in DOS. It compares two files to see if they are identical. If they are not (and the files are text files), it reports the differences line by line. This command has two important uses: first, it can compare two versions of a file and report the changes that occurred between them, as a way of tracing these changes. Second, it can be used to verify that a copy or backup was performed successfully (sometimes disk drives and floppies are unreliable). Verification can also be performed by using the /v option with copy and xcopy.

    Make a new directory j:\temp and copy all the files and directories from k:\cs46alab to it. Then delete the j:\temp directory and all of its files.

  68. What commands did you use?
  69. Use dir to find all files contained in k:\cs46alab or any of its subdirectories. What command did you use? How many files did it find? What is the name of the first file it found?

    We have not yet said how to create and edit text files in DOS. There is a DOS editor which is executed by using the command edit (with or without a file name), but it is old and clunky. Much better is to use the same editor as in the rest of Windows -- Notepad -- and it is easy to call from inside DOS just by typing notepad (with or without a file name). Notepad can also be used to view text files.

  70. Use Notepad to display the text file in j:\cs46a. What command did you use?
  71. Now exit Notepad and return to DOS. Copy k:\cs46alab\lab2\coins3.cpp to j:\. Then use Notepad to delete the 29th line. Save the file, exit Notepad, and use fc to compare the new file to the original on the k: drive.

  72. Write down the output produced by fc:
  73. Now delete the coins3.cpp file in j:\ and close the DOS window.

    You can either use the window button to close the DOS window, or you can type exit at the DOS prompt. In some modes, the window button is not visible and you must use exit.

    Copying between DOS and Windows

    We have already discussed the use of the Windows Clipboard to copy or move whole files or directories. The clipboard can also be used to copy text, graphics, or most other kinds of information back and forth between applications. In particular, it is possible to copy information that appears on a DOS screen to the clipboard and then into Notepad, where it can be saved as a file or printed. This will be particularly useful when recording the screen output of DOS commands as well as C++ programs, as we will see in the next lab. For now, we will see how to copy and save the screen results of DOS commands.

    Open a DOS Command Prompt window. Make sure it is not in full screen mode.

  74. What key(s) are used to switch between window mode and full screen mode in a command prompt window?
  75. Display the j:\include directory so that it fits in a single screen.

  76. What command did you use?
  77. Display the Shortcut Menu for the Command Prompt window.

  78. How did you do it?
  79. Select the Edit | Mark option on the Shortcut menu.

  80. What happened to the cursor?
  81. Hit the [Down] arrow key until the cursor is next to the first line beginning "Volume...". Then hold down the [Shift] key and press the [Down] arrow key ten times.

  82. What happened on the screen?
  83. Continue to hold down the [Shift] key and press the [Right] arrow key until you reach past the text of the directory listing. Now hit [Enter].

  84. What happened on the screen?
  85. Run Notepad (either from DOS or from Windows). Once you are in the Notepad window, hit [Ctrl+v].

  86. What happened?
  87. Now you have a copy of the some of the DOS dir output, which you can edit, save as a file, and print. It is also possible to go the other way, that is, copy from a windows application into DOS, but we will not discuss this here.

    Obviously, this method can only be used to copy a single DOS screen to Notepad or another application. To get more than one screen, you will need to use redirection, which is described in Lab 6.

    Doskey

    Doskey is a DOS program that allows for a substantial amount of automation short of using the batch files mentioned previously, which are more complex and are studied in lab 6. When run, doskey modifies DOS so that each keyboard command is stored up in such a way that it can be retrieved by the use of the arrow keys. Such commands can then be edited using the standard editing keys to form new commands, or simply run again if a repeated operation is desired. Often doskey is run as part of the startup of a DOS command line window, but if it isn't there already, you should get in the habit of running it yourself wheneven you open a DOS window. (In Lab 6 we will see how to automate such a process.)

    Open a DOS command prompt window, and type

    doskey /insert

     

    Then put an empty already-formatted floppy disk in drive a: and type

    k:

    dir:

    cd \cs46alab\lab2

    copy *.* a:

    dir a:

    del a:*.*

  88. Now hit the [Up] arrow key several times. What happens?
  89. Reissue the "copy *.* a:" command by hitting [Up] a few times until it reappears, then hit [Enter].

  90. Type d and [F8]. Hit [F8] repeatedly. What happens?
  91. The [F8] key performs a search of the previous commands that start with the text you have already typed. This is often the fastest method for retrieving an old command.

  92. Retrieve the command "cd \cs46alab\lab2". What keys did you hit?
  93. Now change the command to "cd k:\cs46alab\lab2". Simply hit [Home] to get the cursor all the way to the left, then hit the [Right] arrow key three times, insert k:, and hit [Enter].

    Command line editing with doskey is perfectly intuitive. [Home]/[End] move to the beginning and the end of the command line, the left and right arrows move one character at a time, [Ctrl]+ the left and right arrows move one word at a time, [Del]/[Backspace] erases a character, and [Ins] toggles insert mode. (There are two kinds of insert mode: "Insert" and "Overwrite". The most useful is "Insert" mode, since no characters will disappear, but occasionally "Overwrite" mode is useful. Doskey begins normally in "Overwrite" mode, but using the option /insert starts it in "Insert" mode.)

  94. Issue the command "copy *.* j:" using doskey functions. What keys did you hit?
  95. When you make a typo, simply hit the [Up] arrow and fix it.

  96. Type cd k:\cslab\lab2. What happened?

Hit [Up]. Fix up the directory name. Hit [Enter].

Finally, if you look for a command and you don't find what you want, you can clear the command line and start over by hitting [Ctrl+c]. Indeed, this command can be used to stop almost any DOS action that is still in progress.

Checked by lab supervisor

Date __________________

Initials_______________