\HeaderA{fileutils}{File Utilities}{fileutils}
\aliasA{file\_path\_as\_absolute}{fileutils}{file.Rul.path.Rul.as.Rul.absolute}
\aliasA{file\_path\_sans\_ext}{fileutils}{file.Rul.path.Rul.sans.Rul.ext}
\aliasA{file\_test}{fileutils}{file.Rul.test}
\aliasA{list\_files\_with\_exts}{fileutils}{list.Rul.files.Rul.with.Rul.exts}
\aliasA{list\_files\_with\_type}{fileutils}{list.Rul.files.Rul.with.Rul.type}
\keyword{file}{fileutils}
\begin{Description}\relax
Utilities for testing and listing files, and manipulating file paths.
\end{Description}
\begin{Usage}
\begin{verbatim}
file_path_as_absolute(x)
file_path_sans_ext(x)
file_test(op, x, y)
list_files_with_exts(dir, exts, all.files = FALSE, full.names = TRUE)
list_files_with_type(dir, type, all.files = FALSE, full.names = TRUE,
                     OS_subdirs = .OStype())
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x,y}] character vectors giving file paths.
\item[\code{op}] a character string specifying the test to be performed.
Unary tests (only \code{x} is used) are \code{"-f"} (existence and
not being a directory) and \code{"-d"} (existence and directory);
binary tests are \code{"-nt"} (newer than, using the modification
dates) and \code{"-ot"}.
\item[\code{dir}] a character string with the path name to a directory.
\item[\code{exts}] a character vector of possible file extensions.
\item[\code{all.files}] a logical.  If \code{FALSE} (default), only visible
files are considered; if \code{TRUE}, all files are used.
\item[\code{full.names}] a logical indicating whether the full paths of the
files found are returned (default), or just the file names.
\item[\code{type}] a character string giving the \dQuote{type} of the files
to be listed, as characterized by their extensions.  Currently,
possible values are \code{"code"} (R code), \code{"data"} (data
sets), \code{"demo"} (demos), \code{"docs"} (R documentation), and
\code{"vignette"} (vignettes).
\item[\code{OS\_subdirs}] a character vector with the names of OS-specific
subdirectories to possibly include in the listing of R code and
documentation files.  By default, the value of the environment
variable \env{R\_OSTYPE}, or if this is empty, the value of
\code{\LinkA{.Platform}{.Platform}\$OS.type}, is used.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
\code{file\_path\_as\_absolute} turns a possibly relative file path
absolute, performing tilde expansion if necessary.  Currently, only a
single existing path can be given.

\code{file\_path\_sans\_ext} returns the file paths without extensions.
(Only purely alphanumeric extensions are recognized.)

\code{file\_test} performs shell-style file tests.  Note that
\code{\LinkA{file.exists}{file.exists}} only tests for existence (\code{test -e} on
some systems) but not for not being a directory.

\code{list\_files\_with\_exts} returns the paths or names of the files in
directory \code{dir} with extension matching one of the elements of
\code{exts}.  Note that by default, full paths are returned, and that
only visible files are used.

\code{list\_files\_with\_type} returns the paths of the files in \code{dir}
of the given \dQuote{type}, as determined by the extensions recognized
by \R.  When listing R code and documentation files, files in
OS-specific subdirectories are included if present according to the
value of \code{OS\_subdirs}.  Note that by default, full paths are
returned, and that only visible files are used.
\end{Details}
\begin{SeeAlso}\relax
\code{\LinkA{file.path}{file.path}},
\code{\LinkA{file.info}{file.info}},
\code{\LinkA{list.files}{list.files}}
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
dir <- file.path(R.home(), "library", "stats")
file_test("-d", dir)
file_test("-nt", file.path(dir, "R"), file.path(dir, "demo"))
list_files_with_exts(file.path(dir, "demo"), "R")
list_files_with_type(file.path(dir, "demo"), "demo") # the same
file_path_sans_ext(list.files(file.path(R.home(), "modules")))
\end{ExampleCode}
\end{Examples}

