Module pl.path

Path manipulation and file queries.

This is modelled after Python’s os.path library (10.1); see the Guide.

Dependencies: pl.utils, lfs

Functions

isdir (P) is this a directory?
isfile (P) is this a file?.
getsize (P) return size of a file.
exists (P) does a path exist?.
getatime (P) Return the time of last access as the number of seconds since the epoch.
getmtime (P) Return the time of last modification
getctime (P) Return the system’s ctime.
splitpath (P) given a path, return the directory part and a file part.
abspath (P[, pwd]) return an absolute path.
splitext (P) given a path, return the root part and the extension part.
dirname (P) return the directory part of a path
basename (P) return the file part of a path
extension (P) get the extension part of a path.
isabs (P) is this an absolute path?.
join (p1, p2, ...) return the path resulting from combining the individual paths.
normcase (P) normalize the case of a pathname.
normpath (P) normalize a path name.
relpath (P[, start]) relative path from current directory or optional start point
expanduser (P) Replace a starting ‘~’ with the user’s home directory.
tmpname () Return a suitable full path to a new temporary file name.
common_prefix (path1, path2) return the largest common prefix path of two paths.
package_path (mod) return the full path where a particular Lua module would be found.

Fields

dir Lua iterator over the entries of a given directory.
mkdir Creates a directory.
rmdir Removes a directory.
currentdir Get the working directory.
chdir Changes the working directory.
is_windows are we running Windows?
sep path separator for this platform.
dirsep separator for PATH for this platform


Functions

isdir (P)
is this a directory?

Parameters:

isfile (P)
is this a file?.

Parameters:

getsize (P)
return size of a file.

Parameters:

exists (P)
does a path exist?.

Parameters:

Returns:

    the file path if it exists, nil otherwise
getatime (P)
Return the time of last access as the number of seconds since the epoch.

Parameters:

getmtime (P)
Return the time of last modification

Parameters:

getctime (P)
Return the system’s ctime.

Parameters:

splitpath (P)
given a path, return the directory part and a file part. if there’s no directory part, the first value will be empty

Parameters:

abspath (P[, pwd])
return an absolute path.

Parameters:

  • P string A file path
  • pwd string optional start path to use (default is current dir) (optional)
splitext (P)
given a path, return the root part and the extension part. if there’s no extension part, the second value will be empty

Parameters:

Returns:

  1. string root part
  2. string extension part (maybe empty)
dirname (P)
return the directory part of a path

Parameters:

basename (P)
return the file part of a path

Parameters:

extension (P)
get the extension part of a path.

Parameters:

isabs (P)
is this an absolute path?.

Parameters:

join (p1, p2, ...)
return the path resulting from combining the individual paths. if the second (or later) path is absolute, we return the last absolute path (joined with any non-absolute paths following). empty elements (except the last) will be ignored.

Parameters:

normcase (P)
normalize the case of a pathname. On Unix, this returns the path unchanged; for Windows, it converts the path to lowercase, and it also converts forward slashes to backward slashes.

Parameters:

normpath (P)
normalize a path name. A//B, A/./B and A/foo/../B all become A/B.

Parameters:

relpath (P[, start])
relative path from current directory or optional start point

Parameters:

  • P string a path
  • start string optional start point (default current directory) (optional)
expanduser (P)
Replace a starting ‘~’ with the user’s home directory. In windows, if HOME isn’t set, then USERPROFILE is used in preference to HOMEDRIVE HOMEPATH. This is guaranteed to be writeable on all versions of Windows.

Parameters:

tmpname ()
Return a suitable full path to a new temporary file name. unlike os.tmpnam(), it always gives you a writeable path (uses TEMP environment variable on Windows)
common_prefix (path1, path2)
return the largest common prefix path of two paths.

Parameters:

package_path (mod)
return the full path where a particular Lua module would be found. Both package.path and package.cpath is searched, so the result may either be a Lua file or a shared library.

Parameters:

  • mod string name of the module

Returns:

  1. on success: path of module, lua or binary
  2. on error: nil,error string

Fields

dir
Lua iterator over the entries of a given directory. Behaves like lfs.dir
mkdir
Creates a directory.
rmdir
Removes a directory.
currentdir
Get the working directory.
chdir
Changes the working directory.
is_windows
are we running Windows?
sep
path separator for this platform.
dirsep
separator for PATH for this platform
generated by LDoc 1.4.6 Last updated 2017-07-18 16:28:41