<HTML> <HEAD> <!-- Created by texi2html 1.56k + clip patches and <A href="http://www.clip.dia.fi.upm.es/Software">lpdoc</A> from ciao.texi on 28 January 2007 --> <LINK rel="stylesheet" href="ciao.css" type="text/css"> <TITLE>The Ciao Prolog System - File name manipulation</TITLE> </HEAD> <BODY> Go to the <A HREF="ciao_1.html">first</A>, <A HREF="ciao_75.html">previous</A>, <A HREF="ciao_77.html">next</A>, <A HREF="ciao_241.html">last</A> section, <A HREF="ciao_toc.html">table of contents</A>. <P><HR><P> <H1><A NAME="SEC327" HREF="ciao_toc.html#TOC327">File name manipulation</A></H1> <P> <A NAME="IDX4514"></A> <P> <STRONG>Author(s):</STRONG> Daniel Cabeza, Angel Fernandez Pineda. <P> <STRONG>Version:</STRONG> 1.10#7 (2006/4/26, 19:22:13 CEST) <P> <STRONG>Version of last change:</STRONG> 1.3#51 (1999/9/9, 16:28:44 MEST) <P> This library provides some small utilities to handle file name syntax. <UL> <LI><A HREF="ciao_76.html#SEC328">Usage and interface (filenames)</A> <LI><A HREF="ciao_76.html#SEC329">Documentation on exports (filenames)</A> </UL> <H2><A NAME="SEC328" HREF="ciao_toc.html#TOC328">Usage and interface (<CODE>filenames</CODE>)</A></H2> <div class="cartouche"> <UL> <LI><STRONG>Library usage:</STRONG> <CODE>:- use_module(library(filenames)).</CODE> <LI><STRONG>Exports:</STRONG> <UL> <LI><EM>Predicates:</EM> <A NAME="IDX4515"></A> <CODE>no_path_file_name/2</CODE>, <A NAME="IDX4516"></A> <CODE>file_name_extension/3</CODE>, <A NAME="IDX4517"></A> <CODE>basename/2</CODE>, <A NAME="IDX4518"></A> <CODE>extension/2</CODE>. </UL> <LI><STRONG>Other modules used:</STRONG> <UL> <LI><EM>System library modules:</EM> <A NAME="IDX4519"></A> <CODE>lists</CODE>. </UL> </UL> </div class="cartouche"> <H2><A NAME="SEC329" HREF="ciao_toc.html#TOC329">Documentation on exports (<CODE>filenames</CODE>)</A></H2> <P> <A NAME="IDX4520"></A> <A NAME="IDX4521"></A> <DL> <DT><span class="define">PREDICATE:</span> <B>no_path_file_name/2:</B> <DD><A NAME="IDX4522"></A> <P> This predicate will extract the last item (usually the file name) from a given path. <P> The first argument must be instantiated to a string or atom. Whenever the first argument is an atom, the second argument will be an atom. Whenever the first argument is a string, the second argument will be a string. <P> This predicate will fail under any of the following conditions: <UL> <LI>First argument is not an atom, nor a string. <LI>Second argument is not the last given path item (given path is the first argument). </UL> <P> Those are the most usual usages of no_path_file_name/2: <PRE> ?- no_path_file_name_("/home/nexusV/somefile.txt",K). K = "somefile.txt" ? yes ?- no_path_file_name('/home/nexusV/somefile.txt',K). K = 'somefile.txt' ? yes ?- </PRE> <P> <STRONG>Usage:</STRONG> <CODE>no_path_file_name(Path, FileName)</CODE> <UL> <LI><EM>Description:</EM> <CODE>FileName</CODE> is the file corresponding to the given <CODE>Path</CODE>. <LI><EM>Call and exit should be <EM>compatible</EM> with:</EM> <CODE>Path</CODE> is an atom or a string (<CODE>filenames:atom_or_str/1</CODE>) <CODE>FileName</CODE> is an atom or a string (<CODE>filenames:atom_or_str/1</CODE>) </UL> </DL> <P> <A NAME="IDX4523"></A> <A NAME="IDX4524"></A> <DL> <DT><span class="define">PREDICATE:</span> <B>file_name_extension/3:</B> <DD><A NAME="IDX4525"></A> <P> This predicate may be used in two ways: <UL> <LI>To create a file name from its components: name and extension. For instance: <PRE> ?- file_name_extension(File,mywork,'.txt'). File = 'mywork.txt' ? yes ?- </PRE> <LI>To split a file name into its name and extension. For Instance: <PRE> ?- file_name_extension('mywork.txt',A,B). A = mywork, B = '.txt' ? yes ?- </PRE> </UL> <P> Any other usage of file_name_extension/3 will cause the predicate to fail. Notice that valid arguments are accepted both as atoms or strings. <P> <STRONG>Usage:</STRONG> <CODE>file_name_extension(FileName, BaseName, Extension)</CODE> <UL> <LI><EM>Description:</EM> Splits a <CODE>FileName</CODE> into its <CODE>BaseName</CODE> and <CODE>Extension</CODE>. <LI><EM>Call and exit should be <EM>compatible</EM> with:</EM> <CODE>FileName</CODE> is an atom or a string (<CODE>filenames:atom_or_str/1</CODE>) <CODE>BaseName</CODE> is an atom or a string (<CODE>filenames:atom_or_str/1</CODE>) <CODE>Extension</CODE> is an atom or a string (<CODE>filenames:atom_or_str/1</CODE>) </UL> </DL> <P> <A NAME="IDX4526"></A> <A NAME="IDX4527"></A> <DL> <DT><span class="define">PREDICATE:</span> <B>basename/2:</B> <DD><A NAME="IDX4528"></A> <P> <CODE>basename(FileName, BaseName)</CODE> <P> <CODE>BaseName</CODE> is <CODE>FileName</CODE> without extension. Equivalent to <CODE>file_name_extension(FileName,BaseName,_)</CODE>. Useful to extract the base name of a file using functional syntax. <P> <STRONG>Usage:</STRONG> <UL> <LI><EM>Calls should, and exit will be compatible with:</EM> <CODE>FileName</CODE> is an atom or a string (<CODE>filenames:atom_or_str/1</CODE>) <CODE>BaseName</CODE> is an atom or a string (<CODE>filenames:atom_or_str/1</CODE>) </UL> </DL> <P> <A NAME="IDX4529"></A> <A NAME="IDX4530"></A> <DL> <DT><span class="define">PREDICATE:</span> <B>extension/2:</B> <DD><A NAME="IDX4531"></A> <P> <CODE>extension(FileName, Extension)</CODE> <P> <CODE>Extension</CODE> is the extension (suffix) of <CODE>FileName</CODE>. Equivalent to <CODE>file_name_extension(FileName,_,Extension)</CODE>. Useful to extract the extension of a file using functional syntax. <P> <STRONG>Usage:</STRONG> <UL> <LI><EM>Calls should, and exit will be compatible with:</EM> <CODE>FileName</CODE> is an atom or a string (<CODE>filenames:atom_or_str/1</CODE>) <CODE>Extension</CODE> is an atom or a string (<CODE>filenames:atom_or_str/1</CODE>) </UL> </DL> <P><HR><P> Go to the <A HREF="ciao_1.html">first</A>, <A HREF="ciao_75.html">previous</A>, <A HREF="ciao_77.html">next</A>, <A HREF="ciao_241.html">last</A> section, <A HREF="ciao_toc.html">table of contents</A>. </BODY> </HTML>