HANDLING COMPUTER FILES
HANDLING COMPUTER FILES
FILE CONTENTS
All information in a file is always in binary form or a series of ones
and zeros. A document includes any file you have created. It can be a true text
document, sound file, graphics, images, or any other type of information the
computer can create, store, or size from the internet.
PROGRAM FILES
They contain instructions for the computer’s microprocessor and tell the
computer what to do.
DATA FILES: These
include all other files on disk that are not exactly programs or documents.
These include support files for programs, temporary files, and other random
stuff that must be saved inside the computer.
SEMANTICS
Although the way
programs manipulate files varies according to the operating system and file
system involved, the following operations are typical:
(i) Creating a
file with a given name.
(ii) Setting
attributes that control operations on the file.
(iii) Opening a
file to use its content.
(iv) Reading or
updating the content.
(v) Committing updated contents to durable
storage
Closing the file,
thereby losing access until it is opened again.
IDENTIFYING AND
ORGANIZING FILES
In modern computer
system, files are typically accessed using names also known as file name. Most
computers organize files into hierarchies using folders, directories or
catalogs. The concept is the same irrespective of the terminology used. Each
folder can contain an arbitrary number of files, and it can also contain other
folders. These other folders are referred to as sub folders. Sub folders can
contain still more files and folders and so on, thus building a tree – like
structure in which one “master folder” can contain any number of levels of
other folders and files.
BASIC FILE
OPERATIONS
The basic file
operations are:
(i)
Create (The act of making new
file).
(ii)
Delete (To remove a file from a
disk).
(iii)
Retrieve (To find a file and
bring it back).
(iv)
Copy (To produce something so
that it is the same as an original piece of work)
(v)
View (See the file in a
folder).
(vi)
Update (To make something more
suitable for use now by adding new information or changing design).
(vii)
Open (To open a file for
editing).
(viii)
Close (To close the edited
file).
CREATING A SEQUENTIAL FILE
These are the ways
to organize data in a sequential file:
1.
Choose a DOS file name. Some
examples are INCOME.86, CUSTOMER.DAT and FORT500.
2.
Choose a number from 1 through
255 to be the reference number of the file. While the file is in use, it will
be identified by this number.
3.
Execute the statement
OPEN filename FOR OUTPUT AS #n
Where n is the reference number.
4.
Place data into the file with
the WRITE*statement. If a$ is a string, then the statement
WRITE #n, a$
writes string a$ surrounded by quotation marks into
the file . If c is a number then the statement
WRITE #n, c
writes the number c, without any
leading or trailing spaces, into file number n. The statement
WRITE #n, a$, c
writes a$ and c as before, but comma
separating them. Similarly, if the statement WRITE*n is followed by a list of
several strings and / or numbers separated by commas, then all the string and
numbers appear as before, separated by
commas. After each WRITE* statement is executed, the characters f and El are
placed into the file.
5.
After all the data have been
recorded in the file, execute
CLOSE #n
Where n is the reference number. This
statement breaks the communication line with the file and dissociates the
number n from the file.
Example: Write a
program to create the file. Use EOD as a sentinel to indicate that all the data
has been read.
Solution
REM Create the
file YOB.DAT and record some data into it
OPEN “YOB.DAT” FOR
OUTPUT AS #1
READ name$, year
DO WHILE name$,
year <> “EOD”
WRITE #1, name$,
year
READ name$, year
LOOP
CLOSE #1
REM ----Data:
name, year of birth
DATA Barbra, 1942
DATA Ringo, 1940
DATA Sylvester,
1946
DATA EOD, 0
END
Comments
Post a Comment