Chapter 11 File IO
11.1 File System¶
Operating systems organize data in a hard drive as files. Each file contains a certain type of data. For example, a music track can be stored as an mp3 file, a video clip can be stored as an mpeg file, and a text document can be stored as a txt file. Application programs are also files. In Windows, for example, application programs such as Firefox are stored as executable files. Python programs are a special type of text document, stored as py files.
The type of a file, such as as mp3 and txt, is typically reflected by the last part of the file name, which is called the extension name. The extension name is separated from the main file name by a dot (.). For example, in the file name “readme.txt”, the main file name is “readme” and the extension name is “txt”, indicating that the corresponding file is a text file. In the file name “hello.py”, the main file name is “hello”, and the extension name is “py”, indicating that the file is a Python source file.
Files are organized using folders, which are containers of files and other folders. In a file system, folders are organized in a hierarchy. There is only one folder that is not contained by another folder, and it is called the root folder. Except for the root folder, each folder belongs to another folder, which is typically called the parent folder of the folder. Such a hierarchical structure is called a tree.
In the tree structure of a file system, each file can be identified by the path from the root folder to the file.
In Windows, back slashes (\) are used as the path deliminator symbol. In Linux and Max OS, slashes (/) are used as the path deliminator.
In Windows, a hard drive can be split into several volumes, each having its own tree structure of folders. Windows volumes are denoted by letters, starting from ‘C’, followed by a colon (:). For example, ‘C:\folder\file1’ represents a file in the volume ‘C:’, and is different from the file ‘D:\folder1\file1’.
© Copyright 2024 GS Ng.