CS 2 2/25/2015 File Exists?.

Slides:



Advertisements
Similar presentations
Question Bank. Explain the syntax of if else statement? Define Union Define global and local variables with example Concept of recursion with example.
Advertisements

This Week More Types boolean string Modules print statement Writing programs if statement Type boolean.
Introduction to Unix – CS 21 Lecture 11. Lecture Overview Shell Programming Variable Discussion Command line parameters Arithmetic Discussion Control.
© Anselm SpoerriInfo + Web Tech Course Information Technologies Info + Web Tech Course Anselm Spoerri PhD (MIT) Rutgers University
J. Michael Moore Text Files CSCE 110 From James Tam’s material.
James Tam Introduction To Files In Pascal In this section of notes you will learn how to read from and write to files in your Pascal programs.
1 Session-12 CSIT 121 Spring 2006 Test-1 is on March 9 th ; Demo-5 due date extended to March 7 Test-1 is on March 9 th ; Demo-5 due date extended to March.
New Mexico Computer Science For All More Looping in NetLogo Maureen Psaila-Dombrowski.
Flash Video Flash ActionScript 3.0 Introduction to Thomas Lövgren, Flash developer
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
PHP : Hypertext Preprocessor
The Common Dialog Box. Installing the Common Dialog Box May NOT be your standard VB toolbox.
File I/O 11_file_processing.ppt
Shell Programming. Creating Shell Scripts: Some Basic Principles A script name is arbitrary. Choose names that make it easy to quickly identify file function.
Equations Reducible to Quadratic
>> PHP: Insert Query & Form Processing. Insert Query Step 1: Define Form Variables Step 2: Make DB Connection Step 3: Error Handling Step 4: Define the.
Pascal Programming Today Chapter 11 1 Chapter 11.
Exceptions Chapter 16 This chapter explains: What as exception is Why they are useful Java exception facilities.
Slide 1 Using Menu Bar & Common Dialog Boxes. Slide 2 Setting Up the Main Items v First open the form on which you want the menu located v Then start.
THE C PROGRAMMING ENVIRONMENT. Four parts of C environment  Main menu  Editor status line and edit window  Compiler message window  “Hot Keys” quick.
Chapter 4 ADTs Stack and Queue. 4-2 Formal ADT Specifications The Java interface construct lets us collect together method interfaces into a syntactic.
Chapter 5 The Bourne Shell Graham Glass and King Ables, UNIX for Programmers and Users, Third Edition, Pearson Prentice Hall, Notes by Michael Weeks.
Georgia Institute of Technology More on Creating Classes Barb Ericson Georgia Institute of Technology June 2006.
Project CS 116 Section 4 Deadline 04/28 11:59PM Points: 12.
Computer Science 2 Arrays of Records. First Record Program Input an unknown number of Team Names, School names, and Total scores. (While loop) –Output:
Tutorial 2: Homework 1 and Project 1
Microsoft Visual Basic 2005: Reloaded Second Edition
Generics, Exceptions and Undo Command
Grammars and Parsing.
Lesson 08: Files Class Participation: Class Chat: Attendance Code 
Turning method call into an object
Introduction To Repetition The for loop
The Pseudocode Programming Process
CS 3305 System Calls Lecture 7.
INTRODUCTION A key to effective management is high- quality and timely information to support decision making.
Computer Science 2 Hashing
File Handling Programming Guides.
Computer Science II First With files.
Computer Science II First With files.
Sorts on the AP Exam Insertion Sort.
Computer Science 2 Arrays of Records.
Computer Science 2 Review the Bubble Sort
Computer Science 2 Arrays of Records.
Standard Input/Output Stream
Lesson 08: Files Class Chat: Attendance: Participation
Computer Science Sorting.
Python programming exercise
CS288 Lab Exercise 2.
Computer Science 2: Trees
Additional Topics in VB.NET
Computer Science 2 Arrays of Records.
Programming - Buttons Intro to Robotics.
Computer Science 2 Tally Arrays 2/4/2016.
CS 2 Records 2/22/2018.
Programming - Buttons Intro to Robotics.
Computer Science II Second With files.
CodePainter Revolution Trainer Course
Computer Science 2 More Trees.
Computer Science 1 while
Chapter 5 The Bourne Shell
Selection Statements Chapter 3.
Welcome Back CS 2 2/4/2013 On the record (paper) write the following
More Trees 5/9/2-017 Be able to dry run a program that uses trees
Essential Shell Programming
Computer Science 1 while
Dry Run Fix it Write a program
CMPE212 – Reminders Assignment 2 due next Friday.
Intro to Programming (in JavaScript)
Exceptions and Exception Handling
Computer Science II First With files.
Presentation transcript:

CS 2 2/25/2015 File Exists?

Learning Objectives Be able to determine if a file exists before trying to reset the file Write a program using files

Checking if a file exists function FileExists(FileName:string):Boolean; {It returns TRUE if the file exists; otherwise, it returns FALSE. It closes the file if it exists.} var DummyFile: file; Begin {$I-} {This turns off the error detection for file handling} Assign(DummyFile, FileName); Reset(DummyFile); Close(DummyFile); {$I+} {This turns the error checking back on} FileExists:= (IOResult = 0) and (FileName <>’’); End;

Some Pascal File Error Codes IOResult 2: writeln('File not found'); 3: writeln('Path not found'); 4: writeln('Too many open files'); 5: writeln('File access denied'); 100: writeln('Disk read error'); 101: writeln('Disk write error'); 150: writeln('Disk is write protected'); 152: writeln('Drive is not ready'); 154: writeln('CRC error in data'); 156: writeln('Disk seek error'); 157: writeln('Unknown media type'); 162: writeln('Hardware failure'); else writeln('Various error');

Example without declarations function FileExists(FileName: string):Boolean; {It returns TRUE if the file exists; otherwise, it returns FALSE. It closes the file if it exists.} var DummyFile: file; Begin {$I-} {This turns off the error detection for file handling} Assign(DummyFile, FileName); Reset(DummyFile); Close(DummyFile); {$I+} {This turns the error checking back on} FileExists:= (IOResult = 0) and (FileName <>’’); End; If FileExists(‘stuff.dta’) then Writeln(‘The file exists and can be opened with the reset command’); Else Writeln(‘The file does not exist’); End. Can use any string.

To do today and Friday Using what you have learned about files, write a program with the following… Menu Create a new file Check to see if it exists before this Show all the names from the file Check to see if it exists Find if a name is in the file Check Add to an existing file. Quit Push: Let the user pick the file name. Push: Make a file of records to store the name and phone number Push: Sort the information in the file.