Basic File Operations
Following are some of the basic file operations:
1. Create: To make a new file
2. Delete: To remove a file from a disk
3. Retrieve: To find a file and bring it back
4. Copy: To produce a file so that it is the same as the original piece of work
5. View: To see the files in a folder
6. Update: A manipulation involving adding, modifying, or deleting data to
bring a file up-to-date
7. Open: Open a file for editing
8. Close: To exit the edited file.
9. Rename: To change the name of a file
File Insecurity
File security is a feature of a file system which controls which users can
access which files, and places limitations on what users can do to it. If these
measures are not put in place, files would be insecure.
Effects of File Insecurity
The effects of file insecurity are:
1. Result to file loss
2. Data will become unreliable
3. It will lead to data corruption
File Security Methods
(i) Use of backups: This refers to making copies of data so that these
additional copies are used to restore the original after the loss event. It is also
a method of making copies of the file in a separate location so that they can
be restored if something happens to the computer. This can be done by using
removable media such as a rewritable CD, memory card, flash etc.
(ii) The use of antivirus: A virus is a self–replicating program that copies
itself and that can infect other programs by modifying them or their
environment. An anti-virus is software designed to detect and destroy
computer viruses.
(iii) The use of password: A password is a string of characters used for
authenticating a user on a computer system. It can prevent people from
accessing a computer system, account files or parts of files by requiring a user
to enter a password.
(iv) Proper label of storage device: You should label your storage devices
like floppies, CDs, DVDs, Pen drivers etc. So that you know what is exactly
stored in them and so as not to accidentally delete or format them.
(v) File management: file management is the process of maintaining folders,
documents and multimedia into categories and subcategories as desired by a
user.
Sequential File Creation
There are many ways to organize data in a sequential file. One way is by
using BASIC Programming Language.
Steps involved in Creating a Sequential File Using BASIC
1. Choose a DOS file name: A DOS file name is a string consisting of a base
name of at most eight characters followed by an optional extension consisting
of a period and at most three characters. Blank spaces are not allowed. Some
examples of DOS file names 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 used, it will be identified by this number. <br3. Execute the
statement. OPEN file name FOR OUTPUT AS #n. Where n is the reference
number.
4. Place data into the file with the WRITE statement.
5. After all the data have been recorded in the file, execute CLOSE #n</br
Example 1: A program to demonstrate the use of WRITE statement
REM Demonstrate use of WRITE statement
CLS
WRITE “ENIAC”
WRITE 1946
WRITE “ENIAC, 1946
LET a$ = “Eckert”
LET b$ = “Mauchly”
WRITE 14*139, “J.P. “ , a$, b$, “John”
END
[run]
output
ENIAC
1946
ENIAC 1946
1946, J.P. Eckert, Mauchly, John
Example 2: Write a program to create a file EXAMFILE.DAT with marks in
English and Mathematics.
REM a program to create a file EXAMFILE.DAT and record data into it
OPEN “EXAMFILE.DAT” FOR OUTPUT AS #1
READ Maths$, Eng$
DO WHILE names$ <> “EOD”
WRITE #1, names$, Maths$, Eng$
READ names$, Maths$, Eng$
LOOP
CLOSE #1
DATA Joy, 87, 75
DATA Gbenga, 88, 67
DATA Kimi, 77, 70
DATA EOD, 0, 0
END
Accessing a Sequential File
Data stored in a sequential file can be accessed and read in order with the
following steps:
1. Choose a number from 1 to 255 to be the reference number for the file
2. Execute the statement. OPEN filename FOR INPUT AS n. where n is the
reference number
3. Read data from the file with the INPUT statement.
4. After the desired items have been found close the file with the statement
CLOSE #n.
Example: 3 write a program to display the contents of EXAMFILE.DAT
Solution
REM Read data from EXAMFILE.DAT file
OPEN “EXAMFILE.DAT” FOR INPUT AS #1
PRINT “Name”, English”, Mathematics”
DO WHILE NOT EOF (1)
REM process the entire file
INPUT name$, Maths$, Eng$
LOOP
CLOSE #1
END
DIfferences Between Computer files and Manual Files
Computer File Manual File
Computer files are transferred Manual files can be transported through
electronically. physical means
Computer files are difficult to destroy and Manual files can warn off and can be
can last for a long time depleted easily by hand
Difficult to access at all times Easy to access whenever required
Large amount of information can be stored It is difficult to store a large amount of
and transferred information manually
Advantages of Computerized Files
(i) Computer can perform calculations quickly and efficiently.
(ii) Data can be retrieved quickly and easily.
(iii) Documents that are lost can often be retrieved.
(iv) Security is tight and hard to break into.
(v) Makes work easier.
(vi) Quicker to find things and sort things.
(vii) Transactions can be handled more properly by computers than manually.
Limitations of Computerised Files
(i) Computerized filing system is expensive to set up.
(ii) Not effective where there is irregular electric supply.
(iii) Skilled labour with proficiency in computers is required.