Copying Files
This section describes how to copy a single file and a group of files. Copying files creates a duplicate of the original file and does not remove the original file. This is useful for many reasons. For example, if you want to work on a document at home, you can copy it from your computer at work to a floppy disk and then take the floppy disk home.
To copy a file, you will use the copy command. When you use the copy command, you must include two parameters. The first is the location and name of the file you want to copy, or the source. The second is the location to which you want to copy the file, or the destination. You separate the source and destination with a space. The copy command follows this pattern:
copy source destination
In this section, you will copy the EDIT.HLP and EDIT.COM files from the DOS directory to the FRUIT directory. You will specify the source and destination of these files in two different ways. The difference between the two methods is explained at the end of this section.
Before you begin this section, make sure the command prompt looks like the following:
C:\FRUIT>
To copy the EDIT.HLP and EDIT.COM files from the DOS directory to the FRUIT directory
cd\
The command prompt should now look like the following:
C:\>
Change to the DOS directory by typing the following at the command prompt:
cd dos
The command prompt should now look like the following:
C:\DOS>
dir edit.com
A list similar to the following appears:
Volume in drive C is MS-DOS-6
Volume Serial Number is lE49-15E2
Directory of C:\DOS
EDIT Com 413 03-25-93 5:00a
1 file(s) 413 bytes 11999232 bytes free
This shows that the EDIT.COM file is located in the DOS directory. You just specified another parameter with the dir command, one that directs MS-DOS to list only the files that match the filename you specified in the command. Since only one file in the DOS directory can be named EDIT.COM, the directory list includes only that file.
copy c:\dos\edit.com c:\fruit
The following message appears:
1 file(s) copied
The command you just typed copied the file from its source to its destination. By specifying C:\DOS\EDIT.COM as the source, you indicated that MS-DOS would find the source file EDIT.COM on drive C in the DOS directory. By specifying C:\FRUIT as the destination, you indicated that MS-DOS should place the copy of EDIT.COM on drive C in the FRUIT directory.
dir edit.hlp
copy edit.hlp \fruit
The following message appears:
1 file(s) copied
If you forgot to leave a space before typing fruit, the following message will appear:
Access denied
If this message appears, type the command again and leave a space before fruit.
dir \fruit
You should see the two files listed in the FRUIT directory.
Note that you specified the source and destination in the two copy commands differently. In the command you typed in step 4, you specified the source file as C:\DOS\EDIT.COM and the destination directory as C:\FRUIT. Both C:\DOS\EDIT.COM and C:\FRUIT are called full paths because you specified the drive and directory where these files are located. Specifying the full path is the safest way to copy files, because you provide all the information about which file you want to copy and which directory you want to copy it to.
In the copy command you typed in step 6, you specified EDIT.HLP for the source file and FRUIT for the destination directory. These are relative paths. A relative path specifies only the difference between the current drive and directory and the destination of the files you are copying. The following illustration shows how the DOS directory and the FRUIT directory are related:
When you typed the second copy command, you specified the source filename as EDIT.HLP instead of C:\DOS\EDIT.HLP. This is because drive C is the current drive, so you did not have to repeat C: in the path. The DOS directory is the current directory, so you did not have to repeat DOS in the path. You had to specify only the filename.
For the destination directory, you specified the relative path as FRUIT instead of C:\FRUIT. Again, you did not need to specify drive C, because drive C is current. However, the FRUIT directory is not current. To access the FRUIT directory from the current directory, DOS, MS-DOS must first return to the root directory (), and then switch to the FRUIT directory, before copying the file to its new location. Therefore, you typed the path MS-DOS must take to switch between the current directory and the FRUIT directory, or \FRUIT.
Copying a Group of Files
In this section, you will use wildcards to copy a group of files from the DOS directory to the FRUIT directory. In a card game, a wildcard matches any card in the deck. In MS-DOS, the asterisk (*) wildcard matches any character in that position and all the other positions that follow it. If you want to copy a group of files with similar names, using wildcards is easier than copying each file individually.
In this section, you will first view a group of files by using wildcards, and then copy the files using wildcards. Before you begin this section, make sure your command prompt looks like the following:
C:\DOS>
To list all files ending with the extension TXT and copy them from the DOS directory to the FRUIT directory by using wildcards
dir *.txt
Note that there is a space before the asterisk (*), but not after it.
This command directs MS-DOS to list all files and subdirectories in the current directory that end with the extension JXT. The asterisk matches the first character of the filename and all other characters that follow it, up to the period () that separates the name from the TXT extension. A list similar to the following appears:
Volume in drive C is MS-DOS_6
Volume Serial Number is lE49-15E2 Directory of C:\DOS
NETWORKS TXT 8369 11-11-93 5:00a
OS2 TXT 4587 11-11-93 5:00a
README TXT 10858 11-11-93 5:00a
3 file(s) 23814 bytes
MS-DOS lists all the files that end with a TXT extension. The wildcard in your command specified that MS-DOS should ignore the very different beginnings of the files and focus only on the extensions.
Next, you will copy all the files with a TXT extension to the FRUIT directory by using wildcards.
copy *.txt \fruit
This command copies all the files that have the TXT extension from the current directory (DOS) to the FRUIT directory.
cd \fruit
dir
A list similar to the following appears:
Volume in drive C is MS-DOS_6
Volume Serial Number is lE49-15E2 Directory of C:\FRUIT
. <DIR> 09-27-93 11:11p
.. <DIR> 09-27-93 11:11p
EDIT COM 413 11-11-93 5:00a
EDIT HLP 17898 11-11-93 5:00a
NETWORKS TXT 8369 11-11-93 5:00a
OS2 TXT 4587 11-11-93 5:00a
README TXT 10858 11-11-93 5:00a
7 file(s) 42125 bytes
40652800 bytes free
The EDIT.COM and EDIT.HLP files are the files you copied by following the procedure in the previous section. The files with TXT extensions are the ones you just copied by using wildcards.
Renaming Files
This section explains how to rename files. You may want to rename a file if the information in it changes or if you decide you prefer another name.
To rename a file, you will use the ren command. The ren command stands for "rename." When you use the ren command, you must include two parameters.
The first is the file you want to rename, and the second is the new name for the file. You separate the two names with a space. The ren command follows this pattern:
ren oldname newname
In this section, you will rename the README.TXT file.
Before you begin this section, make sure your command prompt looks like the following:
C:\FRUIT>
ren readme.txt peach.txt
dir
The name PEACH.TXT should appear instead of the name README.TXT. It is the same file, but now has a different name.
Renaming a Group of Files
You also can use wildcards to rename a group of files. If you want to rename a group of files that have similar names, using wildcards is easier than renaming the files individually. In this section, you will rename a group of files by using wildcards.
Before beginning this section, make sure your command prompt looks like the following:
C:\FRUIT>
dir edit.*
A list of the files in the FRUIT directory that begin with EDIT appears.
ren edit.* pear.*
This command specifies that all the files that begin with EDIT should be renamed PEAR, but should keep their original extensions.
dir pear.*
When the files were renamed, their extensions remained the same. For example, EDIT.COM became PEAR.COM, and EDIT.HLP became PEAR.HLP.
You can also rename extensions this way. For example, suppose you want to indicate that a group of files ending with a TXT extension are old. You can use wildcards to rename the files so they have the extension OLD.
dir *.txt
ren *.txt *.old
dir
The files that had the extension TXT now have the extension OLD.
Deleting Files
This section explains how to delete, or remove, a file that you no longer want on your disk. If you don’t have very much disk space, deleting files you no longer use is essential.
To delete a file, you will use the del command. The del command stands for "delete."
In this section, you will delete two files using the del command.
Before you begin, make sure your command prompt looks like the following:
C:\FRUIT>
To delete the PEARCOM and PEAR.HLP files
del pear.com
del pear.hlp
dir
The PEAR.COM and PEAR.HLP files should no longer appear in the list.
In this section, you will use wildcards to delete a group of files.
Before you begin this section, make sure your command prompt looks like the following:
C:\FRUIT>
To delete files in the current directory that end with the extension OLD by using wildcards
dir *.old
A list of all the files that end with the extension OLD appears. Make sure that these are the files you want to delete. When you are deleting files by using wildcards, this step is very important. It will prevent you from deleting files accidentally.
del *.old
3. To confirm that all the files with the extension OLD have been deleted, type the following at the command prompt:
dir
The FRUIT directory should contain no files.
Now that the FRUIT directory is empty, you can delete it by using the rd (remove directory) command that you learned to use in "Deleting a Directory" earlier in this chapter.
cd \
dir
or dir /prd fruit
dir
or dir /pThe FRUIT directory should not appear in the directory list.
Formatting a Floppy Disk
When you purchase new floppy disks, you may be required to format them before you can use them. Practice formatting a floppy disk now.
Caution The data on the disk you format will be erased, so make sure you select a disk that does not contain information you may need later.
format a:
This command specifies that you want to format the disk in drive A. When you press ENTER, the following message appears:
Insert new diskette for drive A:
and press ENTER when ready ...
Checking existing disk format
Saving UNFORMAT information
As it formats the disk, MS-DOS displays the percentage of the disk that has been formatted. When the format is complete, the following message appears:
Volume label (11 characters, ENTER for none)?
3. A volume label is a name for your disk. You can give your disk any name you like, as long as it has 11 or fewer characters. For this exercise, type practice and then press ENTER. Information similar to the following appears:
1213952 bytes total disk space
1213952 bytes available on disk
512 bytes in each allocation unit.
2371 allocation units available on disk.
Volume Serial Number is lE49-15E2 Format another (Y/N)?
4. If you have another disk to format, press Y. If not, press N.
Summary
This concludes the MS-DOS tutorial. During this tutorial, you learned how to: