Friday, March 25, 2011

OPERATING SYSTEM BASICS:8 CREATING AND MANAGING FILES With CMD

CREATING AND MANAGING FILES USING COMMAND-LINE


Disk-based systems store and handle related pieces of information in groups called files. The system recognizes and keeps track of the different files in the system by their filenames. Therefore, each file in the system is required to have a filename that is different from that of any other file in the directory.

If two files having the same name were present within the same directory of the system, the computer becomes confused and fails to operate properly. This is because it cannot determine which version of the file is supposed to be worked on.

Each time a new file of information is created, it is necessary to give it a unique filename by which the operating system can identify and store it. Files are created through programming packages or by applications. 

In an MS-DOS environment, there are a few rules that you must remember when creating new filenames. As mentioned, the filename consists of two parts, a name and an extension. The filename is a combination of alphanumeric characters and is between one and eight characters in length. The extension is an optional addition to the name that begins with a period, and is followed by maximum of three characters.


As discussed earlier, extensions often prove useful in describing the content of a file,or in identifying different versions of the same file. If a filename that already exists is used to store another file, the computer will write the information in the new file over that of the old file, assuming that both of them are same. Therefore, only the new file will exist. The information in the old file will be lost.

Many software packages will automatically generate filename extensions for files they create. The software does this so that other parts of the program, which may work with the same file, will be able to identify where the file came from, or what form it is in.


In any event, you should remember the following seven items when assigning and using filenames:

  •  All files must have a filename.
  • All filenames must be different than any other filename in the system or on the disk presently in use.
  • DOS filenames are up to 8 characters long with an optional 3-character extension (separated from the basic filename by a period).
  • When using a filename in a command, you must also use its extension, if one exists.
  • Some special characters are not allowed in filenames. These are: [, ], :, ;, +, =, \, /, >, ? and ,.
  • When informing DOS where to carry out a command, you must indicate it on which disk drive the operation is to be performed. The drive must be specified by its letter name followed by a colon, for example A:, B:, or C:.
  •  The complete and proper way to specify a file is the drive specifier, filename, and the filename extension, in that order, for example B:filename.ext.
The following commands are used to carry out file-level operations.
1. COPY: The file copy command copies a specified file from one place, either disk or directory, to another. For example:
• C:\>COPY A:filename.ext B:filename.ext
• C:\>COPY A:filename.ext B: is used if the file is to have the same name in its new location. The second filename specifier can be omitted.

2. XCOPY: This command copies all files in a directory along with any subdirectories and their files. This command is particularly useful in copying files and directories among disks with different formats. For example from a 1.2-MB disk to a 1.44-MB disk. For example:
• C:\>XCOPY A: B: /s
This command would copy all files and directories from the disk in drive A: except hidden and system files to the disk in drive B:. The /s switch instructs the XCOPY command to copy directories and subdirectories.

3. DEL or ERASE: This command allows the user to remove unwanted files from the disk when typed in at the DOS prompt. For example:
• C:\>DEL filename.ext
• C:\>ERASE B:filename.ext
A great deal of care should be taken when using this command. If a file is erased accidentally, it may not be retrievable.

4. REN: Enables the user to change the name or extension of a filename. For example:
• C:\>REN A:filename.ext newname.ext
• C:\>COPY A:filename.ext B:newname.ext
Using this command changes only its name but not the content of the file. The original filename (but not the file) is deleted. If you wish to retain the original file and filename, a copy command, using different filenames, can be used.

5. TYPE: Shows the content of a designated file on the monitor screen. For example:
• C:\>TYPE AUTOEXEC.BAT will display the content of the
AUTOEXEC.BAT file

6. FC: This file-compare command compares two files to see if they are the same. This operation is normally performed after a file copy has been performed to ensure that the file was duplicated and located correctly. For example:
• C:\>FC A:filename.ext B:
If the filename is changed during the copy operation, the command should be typed as:
• C:\>FC A:filename.ext B:newname.ext

7. ATTRIB: Changes file attributes such as Read-only (+R or –R), Archive (+A or –A), System (+S or –S), and Hidden (+H or –H). The + and – signs are to add or subtract the attribute from the file. For example:
• C:\>ATTRIB +R C:\DOS\memos.doc
This command sets the file MEMOS.DOC as a read-only file. Read-only attributes protect the file from accidentally being overwritten. Similarly, one of the main reasons for giving a file a Hidden attribute is to prevent it from accidentally being erased. The System attribute is reserved by the operating system and marks the file as a system file.

Hint: A common error message encountered when working with command line operations is the bad command or the file name error message. This type of error message generally occurs when the path specified to the location of a file is incorrect or when the file is missing or misspelled.

Keep it up!

            

No comments:

Post a Comment