Practical Nine/Ten

Hybrid Data Structures : Directory Trees

due : 12am (midnight) 28 May 1997


Part One

Write a program to read in the complete directory tree of a disk into memory. Each directory must be stored as a linked list of files, with pointers to further linked lists for sub-directories. The following can be used as the basis for the structure of a node :

class Node
{
public:
   char FileName[13];
   long Size;
   char isDirectory;
   Node *Next;
   Node *Subdirectory;
};

There must be single pointer (root) pointing to the head of the list containing the filenames of the root directory. Use a recursive function to read in and generate the rest of the tree.

Include a method to output the directory tree.

Part Two

Write methods to write the directory tree to file and to read it back into memory. Convert the memory pointers to file pointers (and vice versa) to achieve this.

The file should be stored in the root directory of the drive so that it can be easily found.

Part Three

Write a routine to search through the directory tree on disk for the first directory name corresponding to a given sub-string. eg. "SYS" should find "WINDOWS/SYSTEM".

Then encapsulate this routine into a program to change to a directory by specifying only the first few characters of the directory name.

Your program must take the search string as a command-line parameter and change to the required directory by reading in the directory tree from the disk file created in Part Two.

Sample Output:
c:\> quickcd sys
Quick-CD changing to WINDOWS\SYSTEM
c:\windows\system>

Ideally, this program should also cater for updating of the directory tree stored on disk by use of special parameters (eg. QuickCD /update).