Manipulating Files

After you have set up your directory structure, you can then place files into directories. Most of your files will be program and application files, or data created from the application programs.

In addition, sometimes you will need to create or edit a text file. For example:

  • You need to create a file called LOGON.BAT that specifies that ABC.EXE should run whenever the BAT file is called.

  • You have a file called ACCT.TXT that needs to be renamed ACCT99.TXT.

  • You have a text file that needs to be updated through editing.

The commands below are useful in file manipulation. These commands are covered in greater detail in the following subsections.

Command

Purpose

COPY CON

Lets you create a text file by capturing whatever data is written to the console (screen). This command works well for quickly creating text files.

TYPE

Displays the contents of a text file.

EDIT

Brings up a text editor that has a user-friendly interface for creating and editing text files.

DEL

The DELETE command deletes files that you no longer need.

REN

The RENAME command renames a file.

Note 

If you are creating a small text file, COPY CON can be a timesaver. If you need to create a larger text file or edit an existing text file, use EDIT. If you are trying to create a text-only file, these commands work better than a word processor because a word processor includes formatting information within the file.

Creating a Text File from the Console

You can use the COPY CON command to quickly create a text file from the command prompt. This command is useful if you need to create a small file. The COPY CON command uses this syntax:

COPY CON filename [Press Enter.]

Type the text that the file will contain. [Press Enter.]

Press the Ctrl key and the Z key at the same time. This will appear on the screen as ^Z.

For example, to create a text file containing the sentence, 'This is a sample text file,' you type:

COPY CON TEST.TXT [Enter]

This is a sample text file.

^Z [Enter]

The system will verify with a message saying 1 file(s) copied. The file will be created in the directory of the drive that you are currently in.

click to expand

start sidebar
Test It Out: Using the COPY CON Command

In this exercise, you will create a small text file from the command prompt:

  1. From the C:\WORDDOCS directory, type COPY CON DATA.TXT and press Enter.

  2. Type any data you want.

  3. Press the Ctrl key and the Z key at the same time. Press Enter.

  4. You should receive the following verification:

1 file(s) copied.
end sidebar

Displaying the Contents of a File

To display the contents of a text file, you can use the TYPE command. TYPE redirects the data within the file to the console screen. TYPE uses this syntax:

TYPE drive letter:\directory\filename 

Or if the prompt is already at the correct drive and directory where the file exists, the syntax is

TYPE filename 

ASCII file

A text file that uses the ASCII character set. ASCII is a standard for encoding letters and numbers into the ones and zeros that the computer understands.

click to expand

Note 

You usually use the TYPE command to see the contents of a text or ASCII file. The command does not produce readable information if you use it to display the contents of an executable file or a file generated by most applications.

Tip 

If the text file you are trying to read contains more than a screen of information, the TYPE command can be somewhat frustrating, because it simply scrolls through the file at what seems like light speed. If this is the case, consider reading the file with the EDIT command.

Editing Text Documents

One of the easiest ways to edit and create text files is to use the EDIT command. EDIT is the user-friendly editing program in DOS.

You can call up the EDIT program and then specify which file to open for editing, or you can call up the path and filename you wish to edit when you invoke the EDIT program at the command prompt.

click to expand

start sidebar
Test It Out: Using the EDIT Command
  1. From the C:\> prompt, type EDIT. The EDIT program starts.

  2. Type whatever you want the text file to say.

  3. Press the Alt key and the F key together to access the File Save menu option.

  4. The Save As dialog box appears. Save the file as SAMPLE.TXT and click the OK button.

  5. Exit the EDIT program by pressing Alt+F and then select File Exit.

end sidebar

Deleting a File

After you no longer need a file, you can delete it with the DEL command. DEL is an easy command to use. The syntax is

DEL drive letter:directory\filename 

Or if you are already in the directory in which the file exists, the syntax is

DEL filename 

click to expand

Note 

Third-party DOS utilities-for example, Norton Utilities-can sometimes recover files that have been deleted.

Tip 

If you delete a file in Windows 98, NT, 2000, XP, or Windows Server 2003, you can recover the deleted file from the Recycle Bin.

Warning 

Do not delete files if you are unsure of what they are. They might be program, application, or configuration files you need.

Renaming a File

Use the REN command to rename files, using this syntax:

REN oldname newname 

For example, assume that you have a file called ACCT.TXT that you want to rename ACCT03.TXT. You would use the command shown on the screen here:

click to expand

start sidebar
Test It Out: Using the REN Command

In this exercise, you will create, rename, and then delete a file.

  1. At the C:\ prompt, create a text file called OLD.TXT by using the EDIT or COPY CON command.

  2. At the C:\> prompt, type REN OLD.TXT NEW.TXT and press Enter.

  3. Use the DIR command to verify that your file has been renamed.

  4. At the C:\> prompt, type DEL NEW.TXT and press Enter.

  5. Use the DIR command to verify that your file has been deleted.

end sidebar




MCSA. MCSE 2003 JumpStart. Computer and Network Basics
MCSA/MCSE 2003 JumpStart
ISBN: 078214277X
EAN: 2147483647
Year: 2003
Pages: 203
Authors: Lisa Donald

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net