File and Path Names

A set of standard predicates ease file name handling and enable searching for files on a disk.

(1) filenamepath/3

filenamepath is used to compose and decompose a fully qualified name around its path and file name. It takes three arguments, as follows:

    filenamepath(QualName,Path,Name)            /* (i,o,o)  (o,i,i)*/

filenamepath converts between QualName on one side, and Path and Name on the other. The programs ch11e12.pro and ch11e13.pro contain examples for DOS and UNIX respectively; both examples do essentially the same thing:

/* Program ch12e12.pro */

 

/* Program ch12e13.pro */

This will set Path to C:¡¬VIP¡¬BIN and name to PROLOG.ERR; finally, NewName will be set to C:¡¬VIP¡¬BIN¡¬PROLOG.ERR. Note that under DOS, all Visual Prolog file name handling converts the name to upper case. This is because there has in the past been confusion with respect to upper and lower case versions of some foreign characters.

Please, using the (o,i,i) flow pattern of this predicate,  take into account some special cases described in the filenamepath topic in VDE help.

(2) filenameext/3

filenameext is used to compose and decompose a (fully qualified) file name around its extension, defined by a dot. It takes three arguments, as follows:

    filenameext(Name,BaseName,Ext)              /* (i,o,o)  (o,i,i)*/

Here is the DOS example:

/* Program ch12e14.pro */

This will set BaseName to C:¡¬VIP¡¬BIN¡¬WIN¡¬16¡¬VIP and Ext to .EXE; then NewName is set to C:¡¬VIP¡¬BIN¡¬WIN¡¬16¡¬VIP.EXE and finally NewName1 demonstrates a direct extension override - it isn't necessary to explicitly remove the old extension first. Note that the dot is considered a part of the extension and that - as with filenamepath - in the DOS version, everything is converted to upper case.