O.S. Extended Predicates

The built-in predicates defined so far are part of the core Amzi! implementation. In addition to these, each operating system has a collection of 'extended predicates' that are defined for that environment. These include, for example, predicates that manipulate files and directories and predicates that allow Windows programs to put up message boxes.

Extended predicates are implemented using the Logic Server API, and come with full source code for Logic Server customers. They can be easily supplemented with your own definitions. The operating system dependent predicates are defined in osutil.cpp and are implemented as a Logic Server Extension (.lsx). The compiled file is aosutil.lsx, which is installed in the amzi/bin directory. It can be modified by any customers with the Logic Server.

To load aosutils.lsx, either include a line in the amzi.cfg:

or from Prolog call:

Using the Logic Server, one can add other .lsx's containing custom extended predicates. See the Logic Server reference for details.

File and Directory Name Parameters

The file/path names can be entered as strings, atoms or character lists. Take care to use double backslashes when string_esc is turned on, the default.

chdir(DirL)

chdir attempts to change the current working directory to DirL, which is a character list, atom or string. If the change is successful, chdir/1 suceeds, otherwise it fails. For example:

chdir(DirL, Err)

chdir/2 attempts to change the current working directory to DirL, which is a character list, atom or string. Err is unified with the operating system error code (which is usually 0 for no error). For example:

curdir(DirS)

curdir/1 attempts returns the current directory as a string in DirS. It fails if the operating system is unable to return the pathname. For example:

delfile(PathL, Err)

delfile/2 attempts to delete the file specified by PathL, where PathL is a character list. Err is unified with the operating system error code (which is usually 0 for no error). For example:

mkdir(DirL, Err)

mkdir/2 attempts to create subdirectory DirL, which is a character list, atom or string. Err is unified with the operating system error code (which is usually 0 for no error). For example:

rename(OldName, NewName, Err)

rename/3 renames the OldName file to NewName. Err is the error code returned from rename, which should be 0 if all went well.

rmdir(DirL, Err)

rmdir/2 attempts to remove subdirectory Dir, which is a character list, atom or string. Err is unified with the operating system error code (which is usually 0 for no error). For example:

findfiles(Mask, Attr, FileInfo)

findfiles/3 (Windows only) is used to get file information from the current directory.

Mask is an atom, string or character list giving the pattern to match, such as '*.*' for everything or '*.pro' for all Prolog files.

Attr is an integer defining what type of files to find. The values are: 0 - normal files, 1 - read only, 4 - system files, 8 - label, and 16 - directories. These values can be added together.

FileInfo is a structure with the file information in the format:

findfiles/3 is designed to be backtracked into and fail when there are no more files. So, the query

will write all of the information about the Prolog files in the current directory.

To get a list of file information, findall/3 can be used. For example, to get a list of just the names of the Prolog files

To get a list of directories

findfiles/3 is actually implemented in alib (Prolog built-in predicates) but uses two osutils extended predicates, findfirst/4 and findnext/2 to set up Prolog backtracking.

stat(FileName,Atime,Ctime,Mtime,Size,Mode,NLink,Uid,Gid)

stat/9 (Unix only) given FileName returns access time, change time, modify time, size (all unsigned longs) and mode, number of links, user-id, group-id.

getdrive(Drive)

getdrive/1 (Windows only) returns the current drive as a string. For example:

setdrive(Drive)

setdrive/1 (Windows only) takes a drive specification and sets the current drive to it. For example:

or

get_env_var(VARIABLE, VALUE)

get_env_var/2 (Windows only) gets the value of a system environment variable. For example:

w_getfile(FileStr)

w_getfile/1 calls the standard Windows file open dialog box, and unifies the file name with FileStr. FileStr is a string and the backslashes are all doubled to avoid problems with string_esc. (32-bit Windows platforms only.)

w_msgbox(Term)

w_msgbox/1 writes Term in a Windows message box, with an OK button.

w_tfmsgbox(Term)

w_tfmsgbox/1 write Term in a Windows message box with YES and NO buttons. If the user picks YES, the predicate succeeds, if the user picks NO the predicate fails.

Copyright ©1987-2011 Amzi! inc. All Rights Reserved. Amzi! is a registered trademark and Logic Server is a trademark of Amzi! inc.