Handling Computer Files for SS2

Handling Computer Files for SS2
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 disk
3. Retrieve: To find a file and bring it back
4. Copy: To produce 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.
Sequential File Creation
There are many ways to organize data in a sequential file. One of such ways is by using BASIC Programming.
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.
3. 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
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]
ENIAC
1946
ENIAC 1946
1946, J.P. Eckert, Mauchly, John
Example 2: Write a program to create a file EXAMFILE.DAT with marks of 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 Gbenda, 88, 67
DATA Viola 77, 70
DATA EOD, 0, 0
END
Accessing a Sequential File
Data stored in a sequential file can be read in order and assigned to variables 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
File Insecurity
File security is a feature of a file system which controls which users can access which files, and places limitation on what users can do to it.
Effects of File Insecurity
The effects of file insecurity are:
1. Result to file loss
2. Data unreliable
3. Data corruption
File Security Methods
(i) Use of backups: This is refers to making copies of data so that these additional copies are used to restore the original after 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 happen to the computer. This can be done by using removable media such as 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 such that a call to an infected program implies a call to a virus. An anti-virus is a 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 accessing computer system, account files or parts of files by requiring a user to enter 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 of 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.
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, accounts 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 labor with proficiency in computers is required.