CLOSEFILE
Closes the file named in the identifier once you have finished reading or writing, so data is saved and the file is released. The name must match the one used in OPENFILE.
Understanding CLOSEFILE in IGCSE Computer Science Paper 2
What it does: All three statements use "Names.txt", so CLOSEFILE closes the file that OPENFILE opened. Two files were opened, so each one gets its own CLOSEFILE with its own identifier. The 0478 keyword is CLOSEFILE, followed by the file identifier. CLOSE on its own is not a pseudocode keyword. CLOSEFILE comes after the last WRITEFILE. Once a file is closed you cannot write to it unless you open it again. Closing makes sure written data is stored safely and frees the file for other uses. It does not delete anything. The file identifier is a string, so it needs quotation marks.
Common mistakes: The identifier in CLOSEFILE must match the one used in OPENFILE. "Date.txt" is a different file name, so it should be CLOSEFILE "Data.txt". The file identifier is a string, so it needs quote marks. It should be CLOSEFILE "Data.txt".
Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.
This module's key terms are also in a printable crossword (Modules 489–499) and word search (Modules 479–499).
Take this worksheet further — free with Cloodit
Each concept is reinforced from every angle — learned, then applied, then tested.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
CLOSEFILE "Scores.txt"Fill in the Blanks
Spot the Error
Student with a class code? Join your class →