handling computer files

Post on 13-Jan-2017

271 Views

Category:

Education

2 Downloads

Preview:

Click to see full reader

TRANSCRIPT

HANDLING COMPUTER FILES IMonday, May 1, 2023

LEARNING OUTCOMES:At the end of the lesson, I should be able to:a. Identify computer file contentsb. Identifying and organizing filesc. Semantics of computer filesd. Basic operation on computer filese. Steps involved in creating

FILE CONTENTSAll 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 FILESThey contain instructions for the computer’s microprocessor and tell the computer what to do.

DATA FILESThese 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.

SEMANTICSAlthough 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 storageClosing 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 OPERATIONSThe 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 FILEThese 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 statementOPEN filename FOR OUTPUT AS #nWhere n is the reference number.4. Place data into the file with the WRITE*statement. If a$ is a string, then the statementWRITE #n, a$writes string a$ surrounded by quotation marks into the file . If c is a number then the statementWRITE #n, cwrites the number c, without any leading or trailing spaces, into file number n. The statementWRITE #n, a$, cwrites 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, executeCLOSE #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.SolutionREM Create the file YOB.DAT and record some data into itOPEN “YOB.DAT” FOR OUTPUT AS #1READ name$, yearDO WHILE name$, year <> “EOD”WRITE #1, name$, yearREAD name$, year LOOPCLOSE #1REM ----Data: name, year of birthDATA Barbra, 1942DATA Ringo, 1940DATA Sylvester, 1946DATA EOD, 0END

ASSIGNMENTRead up: “sequential access”.

TERMINOLOGIES1. EOF – end of file2. EOD – end of document

HANDLING COMPUTER FILES IIMonday, May 1, 2023

LEARNING OUTCOMESAt the end of the lesson, I should be able to:a. Access sequential fileb. State effects of file insecurityc. Identify file security methodsd. Advantages of computerized filese. State limitations of computerized files

ACCESS A SEQUENTIAL FILEData stored in a sequential file can read in order and assigned to variables with the following steps:1. Choose a number from 1 through 255 to be the reference number of the file. This number is not necessary to be the same number that was used when the file was recorded.2. Execute the statementOPEN filename FOR INPUT AS #nWhere n is the reference number. This procedure is referred to as opening a file for input. It establishes a communication line between the computer and the disk drive for reading data from the diskette.3. Read data from the file with the INPUT* statement. INPUT* statement assigns data from file to variable.INPUT #n. var1, var2, ……4. After the desired items have been found or all the data has been read from the file, close the file with the statement CLOSE #n.5. Basic function EOF; it tells us if we have reached the end of a file. For example the condition EOF (n) will be true if the end of file n has been reached and false otherwise.

EXAMPLE: Write a program to display a table showing the ages in 1991 of the people in the sequential file YOB.DAT.SolutionREM Process data from YOB.DAT file to find ages in 1991CLSOPEN “YOB.DAT” FOR INPUT AS #5PRINT “NAME”, “Age in 1991”DO WHILE NOT EOF (5)REM Process the entire fileINPUT #5, name$, yearPRINT name$, 1991 – yearREM Display name and age in 1991LOOPCLOSE #5END[run]Name Age in 1991Barbra 49Ringo 51Sylvester 45Johnny 65

PROTECTING FILESMany modern computer systems provide methods for protecting files against accidental and deliberate damage. Computer with multi users implement file permissions to control who may or may not modify, delete or create files and folders. A user may be given permission to modify a file or folder, but not to delete while some may be permitted to only read the contents and not permitted to modify or delete the content.

File security is a feature of your file system which controls which users can access which files, and places limitations on what users can do to files.Effects of file insecurity(a) Data loss: Computer users and many experts often loss data permanently destroyed, with no hope of recovery.

FILE INSECURITY

CAUSES OF DATA LOSSCustomer PerceptionHuman error40%Computer viruses15%Natural Disasters3%Hardware or System Problem28%Software Corruption or Program Problem12%

(b) OverwritingThis is a process of writing a binary set of data on a memory. Data that has been overwritten is generally considered to be unrecovered.

FILE SECURITY METHODS(i) BACK UP: 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) VIRUS: This 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.ANTIVIRUS: This is software to protect your computer from viruses that may try to infect your computer or might have done so.(iii) PASSWORD PROTECTION: It can prevent people accessing computer system, account files or parts of files by requiring a user to enter password.(iv) STORAGE DEVICE LABELING: 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.

ADVANTAGES OF COMPUTERIZED FILES

(i) Computer can form 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.iv. Data are separated and isolatedv. Data are often duplicatedvi. Application program dependentvii. Incompatible data filesviii.They are vulnerable to virus and hacker attacks

ASSIGNMENTItemize the differences between computer files and manual files.

TERMINOLOGIES1. Sequential2. Random3. File access4. Back up5. Overwrite

END OF STUDENT’S NOTE

EXTRA TUTORIALDo not copy this following notes. They are for practice purposes.

BASIC OPERATION ON COMPUTER FILES

Operations on computer files include the following:1. Create2. Delete3. Retrieve4. Copy5. View6. Open7. Update8. Close

CREATING A SEQUENTIAL FILE

The following statements and functions are used with sequential files:CLOSE LOFEOF OPENINPUT# PRINT#LINE INPUT# PRINT# USINGLOC UNLOCKLOCK WRITE#

STEPS INVOLVED IN CREATING SEQUENTIAL FILE

The following program steps are required to create a sequential file and access the data in the file:1.Open the file in output (O) mode. The current program will use this file first for output:OPEN "O",#1,"filename"

2.Write data to the file using the PRINT# or WRITE# statement:PRINT#1,A$ PRINT#1,B$ PRINT#1,C$

3.To access the data in the file, you must close the file and reopen it in input (I) mode:CLOSE #1 OPEN "I",#1,"filename

4.Use the INPUT# or LINE INPUT# statement to read data from the sequential file into the program:INPUT#1,X$,Y$,Z$

EXAMPLE 1CLS10 OPEN "O",#1,"DATA"20 INPUT "NAME";N$30 IF N$="DONE" THEN END40 INPUT "DEPARTMENT";D$50 INPUT "DATE HIRED";H$60 PRINT#1,N$;","D$",";H$70 PRINT:GOTO 20RUN NAME? MICKEY MOUSE DEPARTMENT? AUDIO/VISUAL AIDS DATE HIRED? 01/12/72 NAME? SHERLOCK HOLMES DEPARTMENT? RESEARCH DATE HIRED? 12/03/65 NAME? EBENEEZER SCROOGE DEPARTMENT? ACCOUNTING DATE HIRED? 04/27/78 NAME? SUPER MANN DEPARTMENT? MAINTENANCE DATE HIRED? 08/16/78 NAME? DONEOK

ACCESSING A SEQUENTIAL FILE

The program in Example 2 accesses the file data, created in the program in Example 1, and displays the name of everyone hired in 1978.

Example 2:CLS10 OPEN "I",#1,"DATA"20 INPUT#1,N$,D$,H$30 IF RIGHT$(H$,2)="78" THEN PRINT N$40 GOTO 2050 CLOSE #1RUN EBENEEZER SCROOGE SUPER MANNInput past end in 20Ok

BASIC FILE PROCESSINGTo read and display files:The table below would be used with a file name “EXAMFILE”.

Matric No. Math English Total Score

0001 50 90 1400002 70 40 1100003 80 60 150

EXAMPLE 310 CLS20 OPEN “EXAMFILE.TXT” FOR INPUT AS #130 PRINT #1 “Matric No. Maths English Total Score”40 PRINT #1 “000150 90 140”50 PRINT #1 “000270 40 110”60 PRINT #1 “000380 60 160”70 CLOSE #180 OPEN “EXAMFILE.TXT” FOR OUTPUT AS #190 DO WHILE NOT EOF(1)100 INPUT #1, text$110 PRINT text$120 LOOP130 CLOSE #1140 END

END OF TUTORIALThank you

top related