Accessing Directories


Four functions in the File folio provide access to directories and their contents. These functions can enumerate the contents of directories or obtain information about all the currently mounted file systems.

Opening the Directory

You can open a directory to read by specifying the directory's pathname or the directory's item number. OpenDirectoryPathName() opens a directory by specifying its pathname.

Directory *OpenDirectoryPathName( char *thePath )
This function opens a directory, allocates a new Directory structure, and prepares for a traversal of the contents of the directory. It returns a pointer to a Directory structure that or NULL if an error occurs.

OpenDirectoryItem() opens a directory by referencing its item number.

Directory *OpenDirectoryItem( Item openFileItem )
It allocates a new Directory structure, opens the directory, and prepares for a traversal of the contents of the directory. OpenDirectoryItem() returns a pointer to the Directory structure, or NULL if an error occurs. Typically, you obtain the item number of a directory by calling OpenDiskFile() on the directory, or by calling GetDirectory().

Reading the Directory

ReadDirectory() reads the next entry from the specified directory.

int32 ReadDirectory( Directory *dir, DirectoryEntry *de )
This function gets information about the next directory entry, and deposits this information in the supplied DirectoryEntry structure. The contents of this structure can then be examined to get details about the entry. The function returns an error code if all entries in the directory have been processed.

Cleaning Up

CloseDirectory() closes a directory that was previously opened using OpenDirectoryItem() or OpenDirectoryPath().

void CloseDirectory( Directory *dir )
All resources get released.

Finding Mounted File Systems

You can obtain a list of the mounted file systems by scanning the "/" directory. If you open this directory and call ReadDirectory() on it, you iterate through all of the currently mounted file system. The DirectoryEntry structure will then hold information about the file system.