← IGCSE Computer Science Paper 2

File identifier: the file name as a string

A file identifier is the name of the file, written as a string in double quotes with its extension, such as "FileA.txt". The same identifier is used in every file command.

Understanding File identifier: the file name as a string in IGCSE Computer Science Paper 2

What it does: All three commands use the identical identifier "Data.txt", so they all refer to the same file. "Names.txt" is a string in double quotes that includes the .txt extension, so it is a correct file identifier.

Common mistakes: The file identifier is a string, so it must be in double quotes. Line 3 should be WRITEFILE "Names.txt", Name. The same identifier must be used in every file command. "Dairy.txt" is a different name from "Diary.txt". Line 4 should be CLOSEFILE "Diary.txt".

Class: _____________________  ·  Name: _____________________  ·  Date: _________

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 479–488) 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.

Learning
Duo
Which line uses a correct file identifier?
OPENFILE FileA.txt FOR WRITEOPENFILE "FileA.txt" FOR WRITE
Matches
OPENFILE FileA.txt FOR WRITE
↓
The file identifier has no double quotes. A file identifier is a STRING, so it must be written as "FileA.txt".
Applying
Meanings
Term
"FileA.txt"
Meaning
A file identifier is the name of the file, written as a string in double quotes with its extension, such as "FileA.txt". The same identifier is used in every file command.
Practice
OPENFILE "Scores.txt" FOR WRITE
Testing
Gaps
READFILE "", Score
Check Answer
Spots
2OPENFILE "Names.txt" FOR WRITE
3WRITEFILE Names.txt, Name

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Pufferfish' badge — Error Handler, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. Which line uses a correct file identifier?
A. OPENFILE FileA.txt FOR WRITE
B. OPENFILE "FileA.txt" FOR WRITE ✓
A file identifier is a string, so the file name must be inside double quotes: "FileA.txt".
2. A file identifier is which data type?
A. INTEGER
B. STRING ✓
The file name is text, so the identifier is a STRING value written in double quotes.
3. Which file identifier includes the extension?
A. "Scores.txt" ✓
B. "Scores"
In 0478 pseudocode the identifier includes the extension, such as .txt, so the file type is clear.
4. A program writes to "Names.txt" and later reads the same data back. Which is correct?
A. Use "Names.txt" in every file command ✓
B. Use a different file name for each command
The same identifier must appear in OPENFILE, READFILE, WRITEFILE and CLOSEFILE so they all refer to the same file.
5. Which pair of lines uses the identifier consistently?
A. OPENFILE "Data.txt" FOR WRITE and CLOSEFILE "Data.txt" ✓
B. OPENFILE "Data.txt" FOR WRITE and CLOSEFILE "Info.txt"
CLOSEFILE must use the same identifier as OPENFILE, otherwise it refers to a different file.

Match the Pairs

OPENFILE "FileA.txt" FOR WRITE → Opens the file named FileA.txt so data can be written to it. The file identifier is a string in double quotes.
"Scores.txt" → A file identifier: the file name written as a STRING value, in double quotes, with its extension.
The same file identifier must be used in every file command that works on that file. → OPENFILE "Data.txt" FOR READ READFILE "Data.txt", Line CLOSEFILE "Data.txt"
A file identifier is a STRING value, so the file name goes inside double quotes and includes the extension .txt. → OPENFILE "Names.txt" FOR WRITE
OPENFILE FileA.txt FOR WRITE → The file identifier has no double quotes. A file identifier is a STRING, so it must be written as "FileA.txt".
OPENFILE "Scores" FOR READ CLOSEFILE "Scores.txt" → The identifier is not the same in both commands. The first has no .txt extension, so the commands refer to different files.

Key Term

"FileA.txt"
A file identifier is the name of the file, written as a string in double quotes with its extension, such as "FileA.txt". The same identifier is used in every file command.

Fill in the Blanks

1. OPENFILE "Scores.txt" FOR READ READFILE "Scores.txt", Score
Hint: Type the file name, with its extension, that matches the OPENFILE line. The double quotes are already there.
2. OPENFILE "Names.txt" FOR WRITE
Hint: Type the extension that shows this is a text file.
3. DECLARE FileName : STRING FileName ← "Data.txt" OPENFILE FileName FOR READ
Hint: Type the data type of a variable that holds a file identifier.
4. OPENFILE "Log.txt" FOR WRITE WRITEFILE "Log.txt", "Done" CLOSEFILE "Log.txt"
Hint: Type the same file name, with its extension, that the earlier file commands use. The double quotes are already there.
5. FileName ← "Data.txt" OPENFILE FileName FOR READ READFILE FileName, Line
Hint: Type the variable that stores the file identifier.

Spot the Error

Question 1
A DECLARE Name : STRING
B OPENFILE "Names.txt" FOR WRITE
C WRITEFILE Names.txt, Name
D CLOSEFILE "Names.txt"
Line C — The file identifier is a string, so it must be in double quotes. Line 3 should be WRITEFILE "Names.txt", Name.
Question 2
A DECLARE Line : STRING
B OPENFILE "Diary.txt" FOR READ
C READFILE "Diary.txt", Line
D CLOSEFILE "Dairy.txt"
Line D — The same identifier must be used in every file command. "Dairy.txt" is a different name from "Diary.txt". Line 4 should be CLOSEFILE "Diary.txt".
Question 3
A DECLARE Mark : INTEGER
B OPENFILE "Mark.txt" FOR WRITE
C WRITEFILE "Marks.txt", Mark
D CLOSEFILE "Marks.txt"
Line B — The identifier here is "Mark.txt", but the other commands use "Marks.txt". It must be the same in every file command. Line 2 should be OPENFILE "Marks.txt" FOR WRITE.
Question 4
A DECLARE Entry : STRING
B OPENFILE "Log.txt" FOR READ
C READFILE 'Log.txt', Entry
D CLOSEFILE "Log.txt"
Line C — In 0478 pseudocode a string, including a file identifier, is written in double quotes, not single quotes. Line 3 should be READFILE "Log.txt", Entry.
Question 5
A DECLARE Score : INTEGER
B OPENFILE "Quiz.txt" FOR WRITE
C Score ← 15
D WRITEFILE "Quiz.txt, Score
E CLOSEFILE "Quiz.txt"
Line D — The closing double quote after the extension is missing, so the identifier is not a complete string. Line 4 should be WRITEFILE "Quiz.txt", Score.

Student with a class code? Join your class →