In order to retrieve data from a file, the computer needs to know:
It is the job of the OS to maintain this information for other programs, and it does this by providing a file system. The purpose of a file system is to provide programs with a uniform way of storing and retrieving data.
The OS manages how data is organised into files. This makes it easier for the user to see files using programs like the Windows File Explorer or Mac OS X Finder. The OS organises where and how files are stored, deleted, read, found and repaired. It detects errors such as missing disks or incorrect file names, and informs the user that errors have occurred.
Each file has a unique name and the OS maintains a set of look-up tables that relate file names to locations on storage drives.
File systems work in a similar way to the way that libraries organise books. Folders and directories correspond to different sections of the library. Inside each folder can be other folders (sub-sections within a subject) and files (the books themselves). If you need to access a specific file you just need to know how to look for it in the index which describes where each file is located.
Most file systems are hierarchical and contain directories that contain lists of other files. Hierarchical file systems usually have a special directory at the root. It can be imagined to be similar to a tree - the branch points are directories that lead to other files. Data files are at the ends of branches and these include files containing program code.
File systems can become corrupt if a computer is turned off before a program is copied to a new location.