Filename Manipulation Package

This package provides portable functions to manipulate filenames.

When this package is loaded, it also computes a number of useful variables indicating where the various Torch components are installed.
Do not change their values.

Manipulating file names

The following functions can be used to manipulate filenames in a portable way over multiple platforms.

paths.filep(path)

Return a boolean indicating whether path refers to an existing file.

paths.dirp(path)

Return a boolean indicating whether path refers to an existing directory.

paths.basename(path,[suffix])

Return the last path component of path and optionally strip the suffix suffix. This is similar to the well know shell command "basename".

paths.dirname(path)

Return the name of directory containing file path. This is similar to the well known shell command "dirname".

paths.concat([path1,....,pathn])

Concatenates relative filenames.

First this function computes the full filename of path1 relative to the current directory. Then it successively computes the full filenames of arguments path2 to pathn relative to the filename returned for the previous argument. Finally the last result is returned.

Calling this function without argument returns the full name of the current directory.

paths.cwd()

Return the full path of the current directory.

paths.execdir()

Return the name of the directory containing the current Lua executable. When the module paths is first loaded, this information is used to relocate the variables indicating the location of the various Torch components.

paths.tmpname()

Return the name of a temporary file. All the temporaty files whose name was obtained in this way are removed when Lua exits.

This function should be preferred over os.tmpname() because it makes sure that the files are removed on exit. In addition, os.tmpname() under windows often returns filenames for which the user has no permission to write.

Directory functions

The following functions can be used to examine directory contents or manipulate directories.

paths.dir(dname)

Return a table containing the files in directory dname. This function return nil if the specified directory does not exists.

paths.files(dname)

Returns an iterator over the files located in directory dname. This can be used in for expression as shown below:

   for f in paths.files(".") do
     print(f)
   end

paths.mkdir(s)

Create a directory. Returns true on success.

paths.rmdir(s)

Delete an empty directory. Returns true on success.

paths.rmall(s, y)

Recursively delete file or directory s and its contents. Argument y must be string "yes" Returns true on success.

Finding files relative to a Lua script

paths.thisfile([arg])

Calling paths.thisfile() without argument inside a lua file returns returns the full pathname of the file from which it is called. This function always returns nil when called interactively.

Calling paths.thisfile(arg) with a string argument arg returns the full pathname of the file arg relative to the directory containing the file from which function paths.thisfile is invoked. This is useful, for instance, to locate files located in the same directory as a lua script.

paths.dofile(filename)

This function is similar to the standard Lua function dofile but interprets filename relative to the directory containing the file that contains the call to paths.dofile, or to the current directory when paths.dofile is called interactively.

Well known directories

These variables indicate where the various Torch components are installed.
It is not advisable to change their values!

paths.install_prefix

The base directory of the Torch installation.

paths.install_bin

The name of the directory containing the executable programs. Under Windows, this directory also contains the dynamically loadable libraries (.dll).

paths.install_man

The name of the directory containing the unix style manual pages.

paths.install_lib

The name of the directory containing the object code libraries. Under Unix, this directory also contains the dynamically loadable libraries (.so or .dylib).

paths.install_share

The name of the directory containing processor independent data files, such as lua code and other text files.

paths.install_include

The name of the directory containing the include files for the various Torch libraries.

paths.install_hlp

The name of the directory containing the Torch help files.

paths.install_html

The name of the directory containing the HTML version of the Torch help files. These files are generated when you enable the CMake option HTML_DOC.

paths.install_cmake

The name of the directory containing the CMake files used by external Torch modules.

paths.install_lua_path

The name of the directory containing the Lua packages. This directory is used to build variable package.path.

paths.install_lua_cpath

The name of the directory containing the Lua loadable binary modules. This directory is used to build variable package.cpath.

paths.home

The home directory of the current user.

Miscellaneous

paths.uname()

Returns up to three strings describing the operating system. The first string is a system name, e.g., "Windows", "Linux", "Darwin", "FreeBSD", etc. The second string is the network name of this computer. The third string indicates the processor type.

paths.is_win()

Returns true if the operating system is Microsoft Windows.

paths.is_mac()

Returns true if the operating system is Mac OS X.

paths.getregistryvalue(key,subkey,value)

Query a value in the Windows registry value. Causes an error on other systems.

paths.findprogram(progname,...)

Finds an executable program named "progname" and returns its full path. If none is found, continue searching programs named after the following arguments and return the full path of the first match. All the directories specified by the PATH variable are searched. Under windows, this also searches the "App Path" registry entries.