Skip to main content
PREV CLASS NEXT CLASS FRAMES NO FRAMES

 

Class IloOplFile

IloOplFile

Description:

This class creates an abstract representation of a file or directory. It can be used to list the contents of a directory, to check if a given file exists, or to check if a file is a hidden file.

See the Overview for a general presentation of the ILOG Script extensions for OPL.

Example:
execute {
  var path = ".";

  var directory = new IloOplFile(path);

  if( !directory.exists ) {
    writeln( "ERROR: Cannot find specified file" );
  } else if (directory.isDirectory != true) {
    writeln( "ERROR: Not a directory" );
  } else {
    writeln( "It is a directory" + directory.name );
    var file = directory.getFirstFileName();
    // Print the content of the directory
    while ( file!=null ) {
      var entry = new IloOplFile(path + directory.separator + file);
      if (entry.isDirectory) {
        writeln( "Dir  " + entry.name );
      } else {
        writeln( "File " + entry.name );
}
      file = directory.getNextFileName();
    }
  }
}
This example parses the current directory '.' and lists its files and subdirectories. After creating a new instance of IloOplFile(path), you should check that the path is valid using the property exists (if (!directory.exists)). This check must be done before you call any other method of IloOplFile. Calling a method on an invalid IloOplFile will throw an exception saying "Cannot find the specified file".
Iterating properties:
Empty iteration.
Index resolution:
Default behavior.
Available for:
flow control

Constructor Summary
Constructor Attributes Constructor Name and Description
 
IloOplFile(path)
Creates an instance of a new IloOplFile from a path.
Property Summary
Field Attributes Field Name and Description
flow control
Returns the absolute pathname of this file or directory.
flow control
Returns true if the file exists.
flow control
Tests whether the file denoted by this abstract pathname is a directory.
flow control
Returns true if this file or directory is hidden.
flow control
Returns the name of the file or directory denoted by this abstract pathname.
flow control
Returns a system-dependent default name-separator character.
Method Summary
Method Attributes Method Name and Description
flow control
Returns the name of the first file or subdirectory in this directory.
flow control
Returns the name of the next file or subdirectory in this directory, or null if there are no more files.
Constructor Detail
IloOplFile
IloOplFile(path)
Creates an instance of a new IloOplFile from a path.
Parameters:
path - The path of the file or directory; it can be an absolute path or not. For instance "/home/work/", "." or "./..".
Property Detail
absolutePath
{string} absolutePath
Returns the absolute pathname of this file or directory. If the path passed to the constructor is already absolute, it returns name. Otherwise, this pathname is resolved in a system-dependent way. On UNIX systems, a relative pathname is made absolute by resolving it against the current directory. On Microsoft Windows systems, a relative pathname is made absolute by resolving it against the current directory of the drive named by the pathname.
Available for:
flow control

exists
{boolean} exists
Returns true if the file exists.
Available for:
flow control

isDirectory
{boolean} isDirectory
Tests whether the file denoted by this abstract pathname is a directory.
Available for:
flow control

isHidden
{boolean} isHidden
Returns true if this file or directory is hidden. The exact definition of hidden is system-dependent. On UNIX systems, a file is considered to be hidden if its name begins with a period character ('.'). On Microsoft Windows systems, a file is considered to be hidden if it has been marked as such in the file system.
Available for:
flow control

name
{string} name
Returns the name of the file or directory denoted by this abstract pathname. Same as specified to the constructor.
Available for:
flow control

separator
{string} separator
Returns a system-dependent default name-separator character. The definition of separator is system dependent.
Available for:
flow control
Method Detail
getFirstFileName
{string} getFirstFileName()
Returns the name of the first file or subdirectory in this directory. If there is no file or subdirectory, it returns null.
Returns:
The name of the first file or subdirectory in this directory.
Available for:
flow control

getNextFileName
{string} getNextFileName()
Returns the name of the next file or subdirectory in this directory, or null if there are no more files.
Returns:
The name of the next file or subdirectory in this directory.
Available for:
flow control

©Copyright IBM Corp. 1987-2011.