IloOplFile
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.
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();
}
}
}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".| Constructor Attributes | Constructor Name and Description |
|---|---|
|
IloOplFile(path)
Creates an instance of a new
IloOplFile from a path. |
| 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 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. |
IloOplFile from a path.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.
true if the file exists.
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.
null.
null if there are no more files.