Module path

Usage:

     local PATH = require "path"
    
     -- suppose we run on windows
     assert(PATH.IS_WINDOWS)
    
     -- we can use system dependet function
     print(PATH.user_home())  -- C:\Documents and Settings\Admin
     print(PATH.currentdir()) -- C:\lua\5.1
    
     -- but we can use specific system path notation
     local ftp_path = PATH.new('/')
     print(ftp_path.join("/root", "some", "dir")) -- /root/some/dir
    
     -- All functions specific to system will fail
     assert(not pcall( function() ftp_path.currentdir() end) )

Functions

has_dir_end (P) Returns true if path has trailing path name separator.
remove_dir_end (P) Removes the path name separator from the end of path, if it has it.
ensure_dir_end (P) Appends a path name separator to path if one does not exist.
normalize (P) Normalize a path.
join (...) Join one or more path components.
splitext (P) Split the path into root and extension.
splitpath (P) Split the path into dirname and basename.
split (P) Alias to splitpath.
splitroot (P) Split first path part for absolute path.
splitdrive (P) Split path into drive specification and path.
basename (P) Return the base name of path.
dirname (P) Return the directory name of path.
extension (P) Return the extension of path.
root (P) Return first path part for absolute path.
isfullpath (P) Return `true` if path contain root part.
isabs (P) Alias to isfullpath
user_home () return user_home dir
flags (P) Return file attributes.
tmpdir () Return path to temp directory.
tmpname () Return full path for temp file.
size (P) Return size in bytes for file.
getsize (P) Alias to size
fullpath (P) Return full normalized path.
abspath (P) Alias to fullpath.
exists (P) Return path if path existing in file system.
isdir (P) Return path if path refers to an existing directory.
isfile (P) Return path if path refers to an existing file.
islink (P) Return path if path refers to an existing symbolic link.
isempty (P) Return true if directory is empty.
ctime (P) Return creation file time.
mtime (P) Return last modification file time.
atime (P) Return last access file time.
cdate (P) Return `path.ctime` as `date` object.
mdate (P) Return `path.mtime` as `date` object.
adate (P) Return `path.atime` as `date` object.
getctime (P) Alias to ctime
getmtime (P) Alias to mtime
getatime (P) Alias to atime
mkdir (P) Create new directory.
rmdir (P) Remove empty directory.
remove (P, opt) Remove file or empty directory.
rename (from, to, force) Rename existed file.
copy (from, to, opt) Copy file or directory tree.
currentdir () Return current work directory path.
chdir (P) Change current work directory path.
each (str_file, str_params, func_callback, tbl_option) Iterate over directory tree.
each (str_file, str_params, tbl_option) Iterate over directory tree.
each (str_file, func_callback, tbl_option) Iterate over directory tree.
each (str_file, tbl_option) Iterate over directory tree.
each (func_callback, tbl_option) Iterate over directory tree.

Tables

copy_opt Option table for `path.copy` function.
remove_opt Option table for `path.remove` function.

Fields

DIR_SEP The path separator.
IS_WINDOWS ???


Functions

has_dir_end (P)
Returns true if path has trailing path name separator.

Parameters:

  • P
remove_dir_end (P)
Removes the path name separator from the end of path, if it has it.

Parameters:

  • P
ensure_dir_end (P)
Appends a path name separator to path if one does not exist.

Parameters:

  • P
normalize (P)
Normalize a path. This function normalize path name separators and collaps redundant separators and up-level references. E.g. `/a/fred/../b`, `/a//b`,`/a\\b`, `/a/./b` all normalize to `/a/b`

Parameters:

  • P
join (...)
Join one or more path components. If any component is an absolute path, all previous components are thrown away, and joining continues. If last parameter is empty string then result path will have trailing path name separator.

Parameters:

  • ...
splitext (P)
Split the path into root and extension. If there no extension then returns empty string as extension. If basename starts with dot then

Parameters:

  • P

Usage:

  • path.splitext("/some/file.txt") --> "/some/path", ".txt"
  • path.splitext("/some/.passwords") --> "/some/.passwords", ""
  • path.splitext("/some/.file.passwords") --> "/some/.file", ".passwords"
splitpath (P)
Split the path into dirname and basename.

Parameters:

  • P
split (P)
Alias to splitpath.

Parameters:

  • P
splitroot (P)
Split first path part for absolute path.

Parameters:

  • P
splitdrive (P)
Split path into drive specification and path.

On non Windows systems drive always empty string.

Parameters:

  • P
basename (P)
Return the base name of path.

Parameters:

  • P
dirname (P)
Return the directory name of path.

Parameters:

  • P
extension (P)
Return the extension of path.

Parameters:

  • P
root (P)
Return first path part for absolute path. On Windows this is drive letter (e.g. "c:\\some\path" => "c:"). On *nix this is first directory name (e.g. "/usr/etc" => "/usr").

Parameters:

  • P
isfullpath (P)
Return `true` if path contain root part.

Parameters:

  • P
isabs (P)
Alias to isfullpath

Parameters:

  • P
user_home ()
return user_home dir
flags (P)
Return file attributes. On Windows it is result of GetFileAttributesEx.


depends on `path.fs`

Parameters:

  • P
tmpdir ()
Return path to temp directory. On Windows can use GetTempPath if Alien/FFI/afx have been found On Windows use TMP/TEMP environment variables


depends on `path.fs`

tmpname ()
Return full path for temp file.


depends on `path.fs`

size (P)
Return size in bytes for file.


depends on `path.fs`

Parameters:

  • P
getsize (P)
Alias to size

Parameters:

  • P
fullpath (P)
Return full normalized path.


depends on `path.fs`

Parameters:

  • P
abspath (P)
Alias to fullpath.

Parameters:

  • P
exists (P)
Return path if path existing in file system.


depends on `path.fs`

Parameters:

  • P
isdir (P)
Return path if path refers to an existing directory.


depends on `path.fs`

Parameters:

  • P
isfile (P)
Return path if path refers to an existing file.


depends on `path.fs`

Parameters:

  • P
islink (P)
Return path if path refers to an existing symbolic link.


depends on `path.fs`

Parameters:

  • P
isempty (P)
Return true if directory is empty.


depends on `path.fs`

Parameters:

  • P
ctime (P)
Return creation file time. On *nix this is the time of the last metadata change.


depends on `path.fs`

Parameters:

  • P
mtime (P)
Return last modification file time.


depends on `path.fs`

Parameters:

  • P
atime (P)
Return last access file time.


depends on `path.fs`

Parameters:

  • P
cdate (P)
Return `path.ctime` as `date` object.


depends on `path.fs` and LuaDate

Parameters:

  • P
mdate (P)
Return `path.mtime` as `date` object.


depends on `path.fs` and LuaDate

Parameters:

  • P
adate (P)
Return `path.atime` as `date` object.


depends on `path.fs` and LuaDate

Parameters:

  • P
getctime (P)
Alias to ctime

Parameters:

  • P
getmtime (P)
Alias to mtime

Parameters:

  • P
getatime (P)
Alias to atime

Parameters:

  • P
mkdir (P)
Create new directory. This function also creates all nested directories if needed.


depends on `path.fs`

Parameters:

  • P
rmdir (P)
Remove empty directory.


depends on `path.fs`

Parameters:

  • P
remove (P, opt)
Remove file or empty directory.

Parameters:

rename (from, to, force)
Rename existed file.


depends on `path.fs`

Parameters:

  • from
  • to
  • force
copy (from, to, opt)
Copy file or directory tree.

Parameters:

currentdir ()
Return current work directory path.


depends on `path.fs`

chdir (P)
Change current work directory path.


depends on `path.fs`

Parameters:

  • P
each (str_file, str_params, func_callback, tbl_option)
Iterate over directory tree.


depends on `path.fs`

Parameters:

  • str_file
  • str_params
  • func_callback
  • tbl_option

See also:

Usage:

  •  -- clean currentdir
     path.each("./*", "f", path.remove, {
       delay = true;   -- use snapshot of directory
       recurse = true; -- include subdirs
       reverse = true; -- subdirs at first
     })
  •  -- clean only files in currentdir
     path.each("./*", "f", path.remove, {skipdirs = true; delay = true})
each (str_file, str_params, tbl_option)
Iterate over directory tree.


depends on `path.fs`

Parameters:

  • str_file
  • str_params
  • tbl_option

See also:

Usage:

     -- clean currentdir
     for fullpath in path.each("./*", "f", {
       delay = true;   -- use snapshot of directory
       recurse = true; -- include subdirs
       reverse = true; -- subdirs at first
     })do path.remove(fullpath) end
each (str_file, func_callback, tbl_option)
Iterate over directory tree.


depends on `path.fs`

Parameters:

  • str_file
  • func_callback
  • tbl_option

See also:

Usage:

     -- clean currentdir. for example we also retreave file mode
     path.each("./*", function(P, mode)
       if mode == 'directory' then
         path.rmdir(P)
       else
         path.remove(P)
       end
     end,{
       param = "fm";   -- request full path and mode
       delay = true;   -- use snapshot of directory
       recurse = true; -- include subdirs
       reverse = true; -- subdirs at first
     })
each (str_file, tbl_option)
Iterate over directory tree. This is common version of function.


depends on `path.fs`

Parameters:

  • str_file
  • tbl_option

See also:

Usage:

     -- clean currentdir
     path.each("./*", {
       callback = path.remove,
       param = "f";    -- request full path
       delay = true;   -- use snapshot of directory
       recurse = true; -- include subdirs
       reverse = true; -- subdirs at first
     })
each (func_callback, tbl_option)
Iterate over directory tree.


depends on `path.fs`

Parameters:

  • func_callback
  • tbl_option

See also:

Tables

copy_opt
Option table for `path.copy` function.

Fields:

  • delay boolean (default false)
  • recurse boolean (default false)
  • skipdirs boolean (default false)
  • skipfiles boolean (default false)
  • accept callable (default function(src)
  • error callable (default function(err)

See also:

remove_opt
Option table for `path.remove` function.

Fields:

  • delay boolean (default true)
  • recurse boolean (default false)
  • skipdirs boolean (default false)
  • skipfiles boolean (default false)
  • accept callable (default function(src)
  • error callable (default function(err)

See also:

Fields

DIR_SEP
The path separator.
IS_WINDOWS
???
generated by LDoc 1.4.0