The PDirectory Class


Overview

This class is a helper class to help you manage directories. You can set the class to point to a directory, you can append more directory names to the current one. You can even find a special OS directory, such as the users settings directory.


PDirectory

Derived from: None

Declared in: PDirectory.h


PDirectory Constructor and Destructor


PDirectory()

          PDirectory(void);

          PDirectory(PString name);

The first version of the constructor will just initialize the class. The class doesn't point to any directory, so you need to call the SetDirectory() or FindDirectory() functions before you can use it.

The second version initialize the class with the directory name you give.


~PDirectory()

          virtual ~PDirectory(void);

Frees allocated memory.


PDirectory Member Functions


Append()

          void Append(PString name);

This function will append the directory names you give as the argument to the current one.


Contains()

          bool Contains(PString name, PEntryType type = pAny);
             throw(PFileException);

If you want to check to see if a file or directory is stored in the current directory, you can use this function. It will search in the directory you have set the class to point to. It can search for different types of entries. The arguments are the name of the entry to search for and the type of the entry. The function will return true if the entry exists, else it will return false. The type can be any of the following:

 pAny  This means you don't care what type of entry you search for.
 pFile  The entry you search for, has to be a file.
 pDirectory  The entry you search for, has to be a directory.
 pLink  The entry you search for, has to be a link.


EndEnum()

          void EndEnum(void);

This function will free all the memory allocated needed to enumerate the current directory. Call this function when you're done with the enumeration.


FindDirectory()

          void FindDirectory(PFindType type);
             throw(PFileException);
             throw(PSystemException);

This function is a very helpful function. It will set the class to point to a OS specific directory. You can e.g. call this function to get the directory where you need to store user settings. The argument is the type of directory you want. You can select between one of these:

 pLaunch  This is the directory where you application was launch from. It's the directory where you application is stored.
 pSettings  This is the directory where the user settings files are stored.


GetDirectory()

          PString GetDirectory(void) const;

This function will return the directory name the class points to at the moment. This can be used if you have called the FindDirectory() function and you then want the name of the directory.


GetDirectoryPart()

          static PString GetDirectoryPart(PString path);

This function will return the directory part of the path you give. If the path only contain a filename, an empty string will be returned.


GetFilePart()

          static PString GetFilePart(PString path);

This function will return the file part of the path you give. If the path only contain a directory, an empty string will be returned.


GetNextEntry()

          bool GetNextEntry(PString &name, PEntryType &type);
             throw(PFileException);

This function will return the next entry in an enumeration. Before you call this function, you have to call the InitEnum() function. When you're done with the enumeration, call the EndEnum() function to cleanup. If the function returns a entry, it will return true and set the entry information in the variables given. If there isn't anymore entries left, it will return false. You can then consider that the enumeration is done. The arguments is a reference where the name and type of the returned entry is stored.


InitEnum()

          void InitEnum(PEntryType type);
             throw(PFileException);

This function is the first function you need to call, if you want to enumerate the current directory. It will initialize all the intern stuff needed to enumarate. After you have called this function, you can call the GetNextEntry() function. The argument is the type of the entries you want returned. The type can be any of the following:

 pAny  This means you want any type returned.
 pFile  You will only get files returned.
 pDirectory  You will only get directories returned.
 pLink  You will only get links returned


SetDirectory()

          void SetDirectory(PString name);

This function will change the class to point to a new directory. The directory is the name argument you give. The function will make sure that the name ends with a slash. If it doesn't, it will append one before it use it.


CreateDirectory()

          void CreateDirectory(void) const;
             throw(PFileException);

This function will create all the directories missing in the directory path the class points to.


The PolyKit developer documentation.
This documentation was written by Thomas Neumann.
© Copyright 1998-1999 by PolyCode.