company logo

Accessing file system directories

The data access to file system directories is supported by appropriate property handles. There is a direct way for accessing directories opening the DirectoryEntry extent. One may, however, also define an extend that inherits from DirectoryEntry data type.

Directory access supports reading directories, only. One cannot update or create new directory entries. When reading directory entries, those will be converted into a system independent format described in the DirectoryEntry.

Directory entries may be accessed recursively, i.e. when a directory entry refers to a sub directory, one may access sub directory entries via the subentries property.

Direct directory access

In order to access directories without providing data model extensions, one may open a property handle for the DirectoryEntry extent. Before opening the property handle, the DirectoryEntry option has to be set to the directory path and the filter mask. When no dictionary path has been set, the current directory is used. When no filter mask is set, no files will be selected from the directory.

Directory entries are ordered by name. This allows accessing entries from the directory by name or position.

The example below shows, how a dictionary may be accessed recursively. In order to access the dictionary this way, any data source has to be opened (e.g. DATASOURCE=Sample or by referring to dictionary and database as in the example below). When opening the DictionaryEntry extent before setting the dictionary path (as in the example below), the property handle needs a refresh in order to allocate the proper dictionary path as being set in the option.

The OSI functions below may be called as:

OSI osi-script -SP(dir_path)

The osi-script file is the the file with the example below. dir_path is theroot directory for starting recursive directory listing.

DICTIONARY='...Sample.dev';

DATABASE='...Sample.dat';

COLLECTION void DirectoryEntry::ListEntries (STRING indent) {

  while( next() ) {

    Message(indent + name);

if ( directory )

  subentries.ListEntries(indent+'  ');

}

void main (STRING dirpath) {

VARIABLES

  set<DirectoryEntry>  &dir = DirectoryEntry;

  Option                path_opt("DirectoryEntry");

PROCESS

   path_opt.assign(dirpath + '/*.*'); // append filter mask

   dir.refresh();

   dir.ListEntries('');

}

Notes:

One cannot open several directories simultaneously, since changing the option value will change the only data source for the DirectoryEntry extent. In order to access several directories in sequence, one has to change the settings for the DirectoryEntry option and call refresh() for the property handle.

Defining an application extent

In order to access more than one directory root simultaneously, one has to define additional extents in the dictionary or within the application (see example blow). For each extent name created one has to assign the directory path to an option with the extent name.

The OSI function below may be called as:

OSI osi-script -SP(dir_path)

The osi-script file is the the file with the example below. dir_path is the root directory for starting recursive directory listing.

DICTIONARY='...Sample.dev';  // insert proper database location

DATABASE='...Sample.dat';

// functions have to be defined before being referenced!!!

COLLECTION void DirectoryEntry::ListEntries (STRING indent) {

  while( next() ) {

    Message(indent + name);

if ( directory )

  subentries.ListEntries(indent+'  ');

};

void main (STRING dirpath) {

VARIABLES

  set<DirectoryEntry>   dir;

  Option                path_opt("MyDir");

PROCESS

   path_opt.assign(dirpath + '/*.*');

   Application::dictionary.temporaryExtent("DirectoryEntry","MyDir","sk_Name","",false,true);

   dir.open(Application::database,"MyDir",'Update');

   dir.ListEntries('');

};